Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Redux & React.js
- Install required packages
- `npm install --save react-redux redux`
- ## To start using Redux we have to
- * Create store
- * Create actions
- * Create reducer
- ### Store
- `store.js`
- ```
- import { createStore } from 'redux';
- import reducers from './reducers';
- export const store = createStore(reducers);
- ```
- ### Actions
- Actions represent changes of the state. We can change state of the store ony by using actions.
- Create `index.js` inside `actions` folder.
- ```
- export const fetchUserData = () => ({
- type: 'FETCH_USER_DATA`
- });
- ```
- ### Provider
- We provide top level component with redux store in
- `index.js`
- ```
- import { store } from './store';
- import { Provider } from 'react-redux';
- ReactDOM.remder(
- <Provider store={store}>
- <App />
- </Provider>,
- document.getElementById('root)
- );
- ```
Add Comment
Please, Sign In to add comment