Skip to content

Instantly share code, notes, and snippets.

@keyserfaty
Created March 17, 2016 20:57
Show Gist options
  • Select an option

  • Save keyserfaty/28a5c7ee24b8e2fc2812 to your computer and use it in GitHub Desktop.

Select an option

Save keyserfaty/28a5c7ee24b8e2fc2812 to your computer and use it in GitHub Desktop.
Basic redux/react structure
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