我从代码中得到以下错误,我知道这是由下面使用的 useEffect 引起的。但是我不明白是什么原因导致了这个警告,如果有人能解释我这个警告的原因以及我该如何解决它,那将是很大的帮助。我在 useEffect 中使用 props 将值作为参数传递给 main 函数中的组件。在下面的 useEffect 中,我试图将参数 Rest 传递回主组件,传递给 onPickScreen 的链接函数。
ERROR Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
代码
function BarScan(props) {
const [scanned, setScanned] = useState(false);
useEffect(() => {
askForCameraPermission();
}, []);
useEffect(() => {
if(scanned){
props.onPickScreen("Rest"); //Cause of error ?
}
}, [scanned]);
return(
<View>
<Text style={styles.maintext}>Scanned value: {text}</Text>
</View>
);
}
export default BarScan;