Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 反应流错误内部渲染方法_Reactjs_React Native_Flowtype - Fatal编程技术网

Reactjs 反应流错误内部渲染方法

Reactjs 反应流错误内部渲染方法,reactjs,react-native,flowtype,Reactjs,React Native,Flowtype,编辑: 我添加了React.Element作为返回类型,并返回而不是null,但仍然存在相同的错误 我的流量版本是0.53.1 render() { return ( <View style={{ flex: 1 }} > <TabHeader title={strings.tabBarLabelRecommend} /> {this._renderVideoCategory()} </View> )

编辑:
我添加了
React.Element
作为返回类型,并返回
而不是null,但仍然存在相同的错误

我的流量版本是0.53.1

render() {
   return (
     <View style={{ flex: 1 }} >
       <TabHeader title={strings.tabBarLabelRecommend} />
       {this._renderVideoCategory()}
     </View>
   );
}
render(){
返回(
{this.\u renderVideoCategory()}
);
}
以上是我的渲染方法,_renderVideoCategory是:

_renderVideoCategory = (): React.Element<*> => {
  if (!this.props.recommendVideos.length) {
    return <View />;
  }
   this.tabWidth = C.SCREEN_WIDTH / this.props.recommendVideos.count;
   return (
     <TabViewAnimated style={{ flex: 1 }} 
       navigationState={this.state} 
       renderScene={this._renderScene}
       renderHeader={this._renderHeader}
       renderPager={this._renderPager}
       onRequestChangeTab={this._handleChangeTab}
     />
   );
};
\u renderVideoCategory=():React.Element=>{
如果(!this.props.recommendVideos.length){
返回;
}
this.tabWidth=C.SCREEN\u WIDTH/this.props.recommendVideos.count;
返回(
);
};
但是流显示了一个错误:(第150行是
{this.\u renderVideoCategory()}


错误:(150,10)流:确切类型:对象类型。此类型与union不兼容:未定义的| null | boolean | number | string |类型React$Element的类型应用程序|标识符Iterable的类型应用程序

而不是返回null返回空div

if (this.props.recommendVideos.length === 0) {
    return <View/>;
}
if(this.props.recommendVideos.length==0){
返回;
}
编辑

您能否更改将函数声明为的方式

_renderVideoCategory (): React.Element<*>{
    if (this.props.recommendVideos.length === 0) {
        return <View/>;
    }
    this.tabWidth = C.SCREEN_WIDTH / this.props.recommendVideos.count;
    return (
        <TabViewAnimated
              style={{ flex: 1 }}
              navigationState={this.state}
              renderScene={this._renderScene}
              renderHeader={this._renderHeader}
              renderPager={this._renderPager}
              onRequestChangeTab={this._handleChangeTab}
        />
    );
}
\u renderVideoCategory():React.Element{
if(this.props.recommendVideos.length==0){
返回;
}
this.tabWidth=C.SCREEN\u WIDTH/this.props.recommendVideos.count;
返回(
);
}

尝试返回空视图,因为Flow希望您返回React.Element(在示例代码中也有注释):

\u renderVideoCategory=():React.Element=>{
如果(!this.props.recommendVideos.length){
返回;
}
this.tabWidth=C.SCREEN\u WIDTH/this.props.recommendVideos.count;
返回(
);
}

这与您的答案无关。现在我正在学习React Native,我没有找到任何好的站点,你能分享一下你是否知道任何好的站点并且都在一个地方吗?你能精确地知道代码中第150行在哪里吗?@yifan_z第150行有什么?{this.\u renderVideoCategory()}我添加了React.Element作为返回类型,并返回而不是null,但还是有同样的错误。让我们来看看。
_renderVideoCategory = ():React.Element<*> => {
  if (!this.props.recommendVideos.length) {
    return <View />;
  }

  this.tabWidth = C.SCREEN_WIDTH / this.props.recommendVideos.count;

  return (
  <TabViewAnimated
    style={{ flex: 1 }}
    navigationState={this.state}
    renderScene={this._renderScene}
    renderHeader={this._renderHeader}
    renderPager={this._renderPager}
    onRequestChangeTab={this._handleChangeTab}
  />);
}