0
私はReactJS + Redux + Google Cloud Endpointsを使用しています。さて、最初のページの読み込みでは、Cloud Enpoint経由でデータを取得して表示する必要があります。どのように達成されるでしょうか?完全なコード例が評価されました!ReactJS + Redux + Cloudエンドポイントで初期ページデータを取得する
私はReactJS + Redux + Google Cloud Endpointsを使用しています。さて、最初のページの読み込みでは、Cloud Enpoint経由でデータを取得して表示する必要があります。どのように達成されるでしょうか?完全なコード例が評価されました!ReactJS + Redux + Cloudエンドポイントで初期ページデータを取得する
基本的には、空白のスレートを使用してアプリケーションをマウントするか、オーバーレイを使用するか、スピナーをロードしてから、componentDidMount()
の内部にデータを取得します。 〜からthe React docs。 AJAX
経由
ロード初期データがcomponentDidMount内のデータを取得します。応答が到着したら、 データを状態に保存して、UIを更新するレンダリングをトリガーします。
データを非同期にフェッチするときは、componentWillUnmountを使用して、コンポーネントがアンマウントされる前に未解決の要求があるかどうかをキャンセルしてください( )。
この例では、希望のGithubユーザーの最新の要旨をフェッチ:あなたが欲しいものをいくつかの例を教えてください
var UserGist = React.createClass({ getInitialState: function() { return { username: '', lastGistUrl: '' }; }, componentDidMount: function() { this.serverRequest = $.get(this.props.source, function (result) { var lastGist = result[0]; this.setState({ username: lastGist.owner.login, lastGistUrl: lastGist.html_url }); }.bind(this)); }, componentWillUnmount: function() { this.serverRequest.abort(); }, render: function() { return ( <div> {this.state.username}'s last gist is <a href={this.state.lastGistUrl}>here</a>. </div> ); } }); ReactDOM.render( <UserGist source="https://api.github.com/users/octocat/gists" />, mountNode );
、あなたが問題を抱えて感じます – webdeb