2017-06-19 9 views
0

Iレンダリングする前に、サーバーのデータをフェッチする必要があるコンポーネント、持っている:あなたが見ることができるように空の小道具についての警告:なぜそれが起こるのですか?

class BooksManage extends Component { 
    componentWillMount() { 
    const { dispatch, fetchManagePage } = this.props 
    dispatch(fetchManagePage()) 
    } 
    render() { 
    const sections = this.props.books.map((section, index) => { 
     return (
     <div className='row' key={index}> 
      <BookSectionContainer index={index} /> 
     </div> 
    ) 
    }) 
    return (
     <div className='row'> 
     <div className='col-md-8'> 
      {sections} 
      <BookPaginationContainer paginationClass='books' /> 
     </div> 
     <div className='col-md-3'> 
      <div style={{position: 'fixed', width: 'inherit'}}> 
      <EmployeesListContainer /> 
      </div> 
     </div> 
     </div>) 
    } 
} 

が、それはBookPaginationContainerを使用して、期待するいくつかの状態パラメータ:

Warning: Failed prop type: The prop `currentPage` is marked as required in `Paginate`, but its value is `undefined`. 

問題:BookPaginationContainerBooksManageの子であるため、componentWillMount()で達成しようとしているのは、アクションをディスパッチすると必要な状態パラメータがフェッチされるということです。実際に何が起こる

action REQUEST_MANAGE_PAGE @ 18:41:49.770 
Warning: Failed prop type: The prop `currentPage` is marked as required in `Paginate`, but its value is `undefined`. 
action RECEIVE_MANAGE_PAGE @ 19:01:40.327 

をすべてのページの後には正しくレンダリングさが、私はこれをどのように良いですと心配です。

+0

「ページ区切り」コンポーネントはどこにありますか。 –

答えて

0

データが必要なコンポーネントを、そのデータを持つまでレンダリングしないでください。

render() { 
    ... 
    if(!this.props.requireData) { 
    return <div>Loading</div>; 
    } 
    return (
    <div className='row'> 
    ... 
+0

私はアイデアを得るが、私は実際の要素で '読み込み'を変更するために、私が推測するいくつかの余分なコールバックが必要でしょうか? –

+0

あなたのコンポーネントがデータを取得する場所/方法は含まれていないので、言うことは難しいです。反応コンポーネントは、新しい状態や小道具を取得すると自動的に再描画されます。したがって、フェッチディスパッチが必要なデータを状態または小道具にプルする場合、正しい要素で自動的に再レン​​ダリングされます。 –

+0

私は 'connect'を使うので、うまく動作します。 –

関連する問題