store を作る

- store の準備

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

以下を 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

- reducer の作成

https://codesandbox.io/s/mq63n3m9oj

reducers/imageUrls.js

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

reducers/index.js

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

index.js

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

Last updated