Udemy-React-Course
  • Introduction
  • CodeSandbox で作る開発環境
    • CodeSandbox を使う利点
    • GitHub との連携
    • CodeSandbox の構造
  • 初めての React App
    • 最小限の React アプリケーションの実装
    • JSX と React Element
    • ES2015 のアロー関数について
    • React でアロー関数を使用する
    • 初めての React Component
    • ES2015 の import / export
    • export default
    • 2章の復習
  • State を持ったコンポーネント
    • State とは何か
    • ES2015 の class
    • React Class Component の書き方
    • click された時に setState で state を変更する
    • H20 Component 1
    • H20 Component 2
    • H20 Component 3
    • H20 Component 4
    • map と filter
    • map と filter の実践
  • 実践:TodoApp の作成
    • TodoApp の作成
  • 非同期処理, Promise, Ajax
    • HTTP プロトコルと AJAX
    • 非同期処理と Promise
    • JSON を取得し、その内容をレンダリングする React App の作成
  • 実践:API を叩く App
    • Giphy API を使用して、GIF画像検索する React App の作成
  • Redux の導入
    • Redux の概要
    • createStore で store を作る
    • Provider と Connect / store を React で使用する
    • Redux の全体像の確認
    • Presentational Component と Container Component
    • Action Creator
    • Combine Reducer
  • Redux-thunk を用いた非同期処理
    • Redux-thunk で非同期にアクションを発行する
    • Promise を Redux-thunk 上で活用する
  • React + Redux + Redux を用いた Giphy App
    • store を作る
    • Component に store を connect する
    • Search コンポーネントの作成
    • GiphyAPI を叩くメソッドの作成と Redux-thunk を使った非同期処理
    • 改善
  • 補足資料
    • App = ({name}) => name 型のシンタックス / Destructuring assignment
    • Class Component と Functional Component の使いわけ
  • 参考資料と謝辞
Powered by GitBook
On this page
  • - store の準備
  • index.js
  • App.js
  • - reducer の作成
  • reducers/imageUrls.js
  • reducers/index.js
  • index.js
  1. React + Redux + Redux を用いた Giphy App

store を作る

PreviousReact + Redux + Redux を用いた Giphy AppNextComponent に store を connect する

Last updated 7 years ago

- store の準備

以下を dependencies に追加する

  • redux

  • react-redux

  • redux-thunk

index.js

import React from "react";
import { render } from "react-dom";

import App from "./App";

import { createStore } from "redux";

import { Provider } from "react-redux";

// まだ rootReducer がないのでエラーになる
const store = createStore(rootReducer);

render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById("root")
);

App.js

import React from "react";

const App = () => {
  return <div>App</div>;
};

export default App;

- reducer の作成

reducers/imageUrls.js

取得した画像用URLのための reducer

const initialState = [1, 2, 3, 4, 5];

const imageUrls = (state = initialState, action) => {
  switch (action.type) {
    case "RECEIVE_DATA":
      return "data";

    default:
      return state;
  }
};

export default imageUrls;

reducers/index.js

複数の reducer を combineReducers でまとめ上げるためのファイル

import { combineReducers } from "redux";

import imageUrls from "./imageUrls";

export default combineReducers({ imageUrls });

index.js

combineReducers でまとめ上げた reducer を import して、createStore に与える

import rootReducer from "./reducers";
const store = createStore(rootReducer);

// 正常に動いているか確認
console.log(store.getState());

https://codesandbox.io/s/0q54o9lxw0
https://codesandbox.io/s/mq63n3m9oj