![](/img/trans.png)
[英]React-Native / Typescript - undefined is not an object (evaluating 'react_1.default.Component)
[英]TypeError: undefined is not an object (evaluating 'icons.map') React-Native
我正在嘗試從數組icons
渲染一系列圖標,但是當我嘗試返回{icons.map((icon, index) =>(<Icon key = {index} icon={icon}/>))}
,我得到“typeError: undefined is not an object (evalating 'icons.map')”。
這是我正在使用的代碼:
const BottomTabs = ({ icons }) => {
const [activeTab, setActiveTab] = useState('Home')
const Icon = ({icon}) => (
<TouchableOpacity onPress = {() => setActiveTab(icon.name)}>
<Image source = {icon.inactive} style= {styles.icon}/>
</TouchableOpacity>
)
return (
<View>
{ icons.map((icon, index) =>(
<Icon key = {index} icon={icon}/>
))}
</View>
)
}
知道問題可能是什么嗎?
編輯:這就是我的數組通過組件傳遞的方式:
<BottomTabs icons = {bottomTabIcons}/>
這是數組本身的對象的示例:
const bottomTabIcons = [
{
name: 'Home',
active: require('../../assets/home-active.png'),
inactive: require('../../assets/home.png')
}
]
我是否錯誤地將數組通過我的BottomTabs
組件?
您沒有將icons
傳遞給BottomTabs
組件。 檢查調用<BottomTabs icons={icons}>
時是否正確傳遞圖標
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.