如何修复警告:失败的道具类型:提供给"Row"的类型为"array"的道具&qu



我在尝试运行项目时遇到此错误,该项目为警告:失败的道具类型:提供给Row的类型为array的道具style无效,应为object

如何在react native中修复此错误?

如何解决项目中的此错误?任何人都可以帮助我在这里为我的项目解决这个问题。

感谢您的提前帮助!

这是我的代码:

const TT= () => {
const [data, setData] = useState();

const td= [
'ID',
'Name',
'User Name',
'Gmail',
'Phone Number',
'WebSite',
];
const widthArr= [40, 60, 80, 100, 120, 140,];

useEffect(() => {
fetch("https://jsonplaceholder.typicode.com/users")
.then((response) => response.json())
.then((data) => setData(data))
.catch((error) => console.error(error))
}, []);

return (
<View style={styles.container}>        
<ScrollView horizontal={true}>
<View>
<Table style={{ marginTop: 20 }} 
borderStyle={{ borderWidth: 2, borderColor: 'black' }}>
</Table>
<Row 
data={td}
widthArr={widthArr}
style={styles.header}
textStyle={styles.text}
/>
<ScrollView>
<Table borderStyle={{
borderWidth: 2,
borderColor: 'black'
}}>
{data?.map((rowData, index) => (
<Row
key={index}
data={rowData}
widthArr={widthArr}
style={[
styles.row,
index % 2 && {backgroundColor: '#F7F6E7'},
]}
textStyle={styles.text}
/>
))}
</Table>
</ScrollView>
</View>
</ScrollView>
</View>
)
}

我的错误如下:

在此处输入图像描述

如果数组不可接受,可以通过"扩散算子";(...(来覆盖常规样式配置。

<Row
key={index}
data={rowData}
widthArr={widthArr}
style={{
...styles.row,
...(index % 2 && {backgroundColor: '#F7F6E7'})
}}
textStyle={styles.text}
/>

相关内容

最新更新