Guest User

Untitled

a guest
Oct 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. # Redux & React.js
  2. Install required packages
  3. `npm install --save react-redux redux`
  4.  
  5. ## To start using Redux we have to
  6. * Create store
  7. * Create actions
  8. * Create reducer
  9.  
  10. ### Store
  11. `store.js`
  12. ```
  13. import { createStore } from 'redux';
  14. import reducers from './reducers';
  15.  
  16. export const store = createStore(reducers);
  17. ```
  18.  
  19. ### Actions
  20. Actions represent changes of the state. We can change state of the store ony by using actions.
  21. Create `index.js` inside `actions` folder.
  22. ```
  23. export const fetchUserData = () => ({
  24. type: 'FETCH_USER_DATA`
  25. });
  26. ```
  27.  
  28. ### Provider
  29. We provide top level component with redux store in
  30. `index.js`
  31. ```
  32. import { store } from './store';
  33. import { Provider } from 'react-redux';
  34.  
  35. ReactDOM.remder(
  36. <Provider store={store}>
  37. <App />
  38. </Provider>,
  39. document.getElementById('root)
  40. );
  41. ```
Add Comment
Please, Sign In to add comment