GiphyAPI を叩くメソッドの作成と Redux-thunk を使った非同期処理
- GiphyAPI を叩くメソッドの作成
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 を適用する
index.js
- action を作る
actions/getUrls.js
reducers/imageUrls.js
index.js
- Search コンポーネントにメソッドを connect する
containers/Search.js
components/Search.js
App.js
Last updated