Guest User

Untitled

a guest
Nov 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. const {createStore } = Redux;
  2. const { Provider, connect } = ReactRedux;
  3.  
  4. const store = createStore((state={name: 'ron'}, action) => {
  5. switch(action.type) {
  6. case 'changeName': return {name: action.name};
  7. default: return state
  8. }
  9. })
  10.  
  11. const Person = props => {
  12. const {name, dispatch} = props
  13. console.log(`rendering Person due to name changed to ${name}`)
  14. return (
  15. <div>
  16. <p> My name is {name} </p>
  17. <button onClick={ () => dispatch({type: 'changeName', name: 'ron'}) } > Change to Ron </button>
  18. <button onClick={ () => dispatch({type: 'changeName', name: 'john'}) } > Change to John</button>
  19. </div>
  20. )
  21. }
  22.  
  23. const App = connect(state=>state)(Person)
  24.  
  25. ReactDOM.render(
  26. <Provider store={store}><App/></Provider>,
  27. document.getElementById('root')
  28. );
Add Comment
Please, Sign In to add comment