异常
ReactNativeJS: 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.
in RCTView (at View.js:60)
in View (at createAnimatedComponent.js:154)
in AnimatedComponent (at Header.js:443)
in RCTView (at View.js:60)
in View (at Header.js:488)
in RCTView (at View.js:60)
in View (at Header.js:624)
in RCTView (at View.js:60)
省略其他报错指引信息...
分析
问题代码是由类型库(例如flow)发出的报错, 第二个参数的值应该为一个组件,而不是方法,所以会报出此警告。
const showCustomAlert = (
title: string,
costomView: React.Node
) => {
do something...
};
CommonModalView.showCustomAlert(
'确定放弃填写个人信息吗?',
()=> <View></View> // 问题出在这,这边应该传入一个React组件而非回调函数
);
解决
CommonModalView.showCustomAlert(
'确定放弃填写个人信息吗?',
<View></View>
);