GiphyAPI を叩くメソッドの作成と Redux-thunk を使った非同期処理
- GiphyAPI を叩くメソッドの作成
https://codesandbox.io/s/k30no82zo5
dependencies の追加
Axios を dependencies に追加する
APIs/giphyAPI.js
import axios from "axios";
const giphyApi = word => {
const search = word;
const key = "V6AU97qCSCYVmbIC5UDppEiVM1xnuO9E";
const limit = 3;
const url = `https://api.giphy.com/v1/gifs/search?q=${search}&api_key=${key}&limit=${limit}`;
// promise オブジェクトが return されるようにする
return axios.get(url);
};
export default giphyApi;index.js
作ったメソッドを仮に実行する
- redux-thunk を適用する
https://codesandbox.io/s/9zx8nrnzjr
index.js
- action を作る
https://codesandbox.io/s/64rq4lyj23
actions/getUrls.js
reducers/imageUrls.js
reducer の修正
index.js
仮に実行する。
- Search コンポーネントにメソッドを connect する
https://codesandbox.io/s/0or0zq8pvn
containers/Search.js
components/Search.js
App.js
Last updated