2016-08-24 19 views
1

私はリアクターとリアクタールーターを使用していますが、いくつかのページでは、大きなリストをページの(サブコンポーネントとして)レンダリングしています。ページを変更するリンクをクリックすると、すべてのサブコンポーネントがレンダリングされるのを待ちます。これは、クリックとビジュアルフィードバックの間の遅延を意味します。いくつかのサブコンポーネントがレンダリングされるのを待たない簡単な方法はありますか?反応遅延重いサブコンポーネントレンダリング

ベストプラクティスを探していますが、ブール値を使用していて、setTimeout()が唯一の方法です。どうも。

+1

レンダリングを手作業で遅らせることは避けたいのですが、レイジーローディングのようなものを試すことができますか?表示されている場合はリスト内の項目をレンダリングするだけですか?似たようなアプローチ – Geraint

答えて

1

コンポーネントの大きなリストがある場合、それらのコンポーネントのすべてが同時に表示されないことがよくあります。 React Virtualizedを使用すると、実際に表示されるコンポーネントだけをレンダリングできます。

+0

React Virtualizedは実際に私のニーズに少し過剰なようです... https://github.com/onefinestay/react-lazy-renderはちょうど罰金がかかっていたようですが、古くなっています:/ – Cohars

1

は、以下のコードを確認してください:

const LightComponent =() => <div>LightComponent</div> 
 
const HeavyComponent =() => <div>HeavyComponent</div> 
 

 
class App extends React.Component { 
 

 
    constructor(props) { 
 
    super(); 
 
    this.state = { shouldRenderHeavyComponent: false }; 
 
    } 
 
    
 
    componentDidMount() { 
 
    this.setState({ shouldRenderHeavyComponent: true }); 
 
    } 
 
    
 
    render() { 
 
    console.log("Render", this.state.shouldRenderHeavyComponent); 
 
    return (
 
     <div> 
 
     <LightComponent/> 
 
     { this.state.shouldRenderHeavyComponent && <HeavyComponent/> } 
 
     </div> 
 
    ); 
 
    } 
 
} 
 

 
ReactDOM.render(<App/>, document.getElementById('app'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> 
 

 
<div id="app"></div>

+0

これはまったく同じですsetTimeout、さらに、私はcomponentDidMountのsetStateの大ファンではない – Cohars

関連する問題