针对条件渲染组件的React Proptypes警告

时间:2016-12-12 12:31:46

标签: reactjs react-proptypes

假设我有2条路线:

/应用/搜索

/应用/搜索/关键字

第一个路由使用searchBox呈现pageSearch组件。 第二个路由使用text关键字内部呈现相同的pageSearch组件,以及我的ajax请求应从api服务器(图库组件)获取的图像列表。

我的pageSearch组件将获取图片列表:

const data =  []
  render() {
   .....
    const gallery = data.length ? React.cloneElement(children, { data }) : null

    return (
      <View>
        <SearchBox />
        {gallery}
      </View>

但是,如果我从服务器获取一些数据,我只想渲染我的Gallery组件:

warning.js:36Warning: Failed prop type: Required prop `data` was not specified in `Gallery`.
    in Gallery (created by RouterContext)
    in RouterContext (created by Router)
    in ScrollBehaviorContext (created by Router)
    in Router
    in MuiThemeProvider
    in IntlProvider (created by LanguageProvider)
    in LanguageProvider (created by Connect(LanguageProvider))
    in Connect(LanguageProvider)
    in Provider

问题是,当我的路线像/ app / search / keyword并且我没有渲染图库(没有从服务器收到数据)时,我从图库propTypes收到警告:

{{1}}

0 个答案:

没有答案