LoginSignup
15
4

More than 5 years have passed since last update.

Redux で store をどこでも取得する

Last updated at Posted at 2017-06-16

store のメソッドで state を取得、変更するためのイベントなどを発行していますが、store を取得する方法がいろいろあって基本的なことにやっとたどり着いたのでメモ。

1 store を作成

store.js

import { createStore } from 'redux';
import reducers from './reducers';

const store = createStore(reducers);
export default store;

2 store を使う ( state の値を変更したり、取得したり)

hoge.js

// store.js の store を取得
import store from '../../store';


store.dispatch(loadSearchLayout('users', 'User Results'));

で Action 経由 で state の値を変更とか


store.getState()

で store から state の値を取得とかできます。

15
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
4