Javascript 看起来像你';为';重新传递内联函数;组件';屏幕的道具';添加';(例如组件={()=>;<;SomeComponent/>;})
我面临的问题是,react导航向我发出警告,我正在为component prop传递一个内联函数。遵守守则:Javascript 看起来像你';为';重新传递内联函数;组件';屏幕的道具';添加';(例如组件={()=>;<;SomeComponent/>;}),javascript,reactjs,react-native,react-navigation,Javascript,Reactjs,React Native,React Navigation,我面临的问题是,react导航向我发出警告,我正在为component prop传递一个内联函数。遵守守则: const Tab = createBottomTabNavigator(); export default function TabNavigator ({navigation, route}) { return ( <Tab.Navigator initialRouteName="Home" tabBa
const Tab = createBottomTabNavigator();
export default function TabNavigator ({navigation, route}) {
return (
<Tab.Navigator
initialRouteName="Home"
tabBarOptions={{activeTintColor: "#6b6b6b", inactiveTintColor: "#d3d3d3", labelStyle: {fontSize: RFValue(8), top: -5, fontFamily: 'Montserrat-Regular'}, style:{borderTopColor: 'transparent'}}}>
<Tab.Screen
name="Home"
component={Home}
options={{tabBarIcon:({color})=> (<Icon_Home name="home" size={RFValue(20)} color={color}/>)}}/>
<Tab.Screen
name="Kategorien"
component={Categories}
options={{tabBarIcon:({color})=> (<Icon_Categories name="list" size={RFValue(18)} color={color}/>)}}/>
<Tab.Screen
name="Add"
component={() => null}
options={{
tabBarIcon: (props) => (
<View style={{flex: 1, width: "100%"}}>
<TouchableOpacity
style={{flex: 1, justifyContent: "center", alignItems: "center"}}
onPress={async () => {
ActionSheetIOS.showActionSheetWithOptions (
{
options: ["Cancel", "Fotos", "Kamera"],
cameraButtonIndex: 2,
galleryButtonIndex: 1,
cancelButtonIndex: 0
},
async buttonIndex => {
if (buttonIndex === 0) {
} else if (buttonIndex === 1) {
// const {status} = await Permissions.askAsync(Permissions.CAMERA_ROLL)
// if (status == "granted") {
// let result = await ImagePicker.launchImageLibraryAsync();
// if (!result.cancelled) {
// navigation.navigate("AddReceiptScreen", {image: result});
// console.log(result);
// }
// }
console.log("Index 1 pressed.")
} else if (buttonIndex === 2) {
// const {status} = await Permissions.askAsync(Permissions.CAMERA)
// if (status == "granted") {
// // let result = await ImagePicker.launchCameraAsync();
// let result = await imageScanner;
// if (!result.cancelled) {
// navigation.navigate("AddReceiptScreen", {image: result});
// console.log(result);
// }
// }
console.log("Index 2 pressed.")
}
}
)
}}>
<Image
source={Icon_Add}
style={{width: RFValue(35), height: RFValue(35)}}/>
</TouchableOpacity>
</View>
),
tabBarLabel: () => null,
}}/>
<Tab.Screen
name="Detail"
component={Detail}
options={{tabBarIcon:({color})=> (<Icon_Detail name="bar-graph" size={RFValue(18)} color={color}/>)}}/>
<Tab.Screen
name="Profil"
component={Profile}
options={{tabBarIcon:({color})=> (<Icon_Profile name="user-alt" size={RFValue(18)} color={color}/>)}}/>
</Tab.Navigator>
)
}
const Tab=createBottomTabNavigator();
导出默认函数TabNavigator({navigation,route}){
返回(
()}}/>
()}}/>
空}
选择权={{
塔巴瑞康:(道具)=>(
{
ActionSheetIOS.showActionSheetWithOptions(
{
选项:[“取消”、“Fotos”、“Kamera”],
cameraButtonIndex:2,
galleryButtonIndex:1,
取消按钮索引:0
},
异步按钮索引=>{
如果(按钮索引===0){
}否则如果(按钮索引===1){
//const{status}=wait Permissions.askAsync(Permissions.CAMERA_ROLL)
//如果(状态=“已授予”){
//让结果=等待ImagePicker.launchImageLibraryAsync();
//如果(!result.cancelled){
//导航(“AddReceiptScreen”,{image:result});
//控制台日志(结果);
// }
// }
console.log(“按下索引1”)
}否则如果(按钮索引===2){
//const{status}=wait Permissions.askAsync(Permissions.CAMERA)
//如果(状态=“已授予”){
////让结果=等待ImagePicker.launchCameraAsync();
//让结果=等待图像扫描仪;
//如果(!result.cancelled){
//导航(“AddReceiptScreen”,{image:result});
//控制台日志(结果);
// }
// }
log(“按下索引2”)
}
}
)
}}>
),
tabBarLabel:()=>null,
}}/>
()}}/>
()}}/>
)
}
如何解决警告?选项属性不能将函数作为参数。
检查上面的链接以查找选项道具的类型后,我找到了解决方法。我没有使用component={()=>null},而是创建了另一个组件 const AddScreen=()=>{ 返回空 }
并且将这个用于组件。您是:
component={()=>null}
。是的,我不需要任何组件,因为我正在使用ActionSheet作为onPress函数,因此我不需要任何组件。有没有一个具体的解决方案来代替component={()=>null}?提前多谢!选项属性没有将函数作为参数。警告是关于组件道具的。