Created
March 17, 2016 20:57
-
-
Save keyserfaty/28a5c7ee24b8e2fc2812 to your computer and use it in GitHub Desktop.
Basic redux/react structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { render } from 'react-dom'; | |
| import { Provider } from 'react-redux'; | |
| import { createStore } from 'redux'; | |
| import App from './components'; | |
| // REDUCER | |
| function person(state = {}, action) { | |
| switch (action.type) { | |
| case 'CREATE_PERSON': | |
| return `${state} persona creada`; | |
| default: | |
| return state; | |
| } | |
| } | |
| // STORE | |
| let store = createStore(person); | |
| // SUSCRIBER (para obtener el resultado o estado actual del state) | |
| store.subscribe(() => | |
| console.log(store.getState()) | |
| ); | |
| // DISPATCH envia una accion al estado que el store busca en el reducer | |
| store.dispatch({ type: 'CREATE_PERSON' }); | |
| render( | |
| <Provider store={store}> | |
| <App /> | |
| </Provider>, | |
| document.getElementById('root') | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment