Last active
February 12, 2019 07:58
-
-
Save pedroparra/c11d261fedec0b81925f to your computer and use it in GitHub Desktop.
Revisions
-
pedroparra revised this gist
Jan 3, 2016 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -27,6 +27,8 @@ const counter = ({value, clickSumar, clickRestar}) => { }; // Renderizamos el componente. // Cada vez que el stado cambie, el componente // se volverá a renderizar. const render = () => { ReactDOM.render( <Counter @@ -38,3 +40,5 @@ const render = () => { ); }; store.subscribe(render); render(); -
pedroparra created this gist
Jan 3, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { createStore } from 'redux'; // Preparamos nuestra funcion reducer const myReducer = (state = 0, action) => { switch(action.type) { case 'sumar': return state + 1; case 'restar': return state - 1; default: return state; } } // Inicializamos el store pasándole el reducer const store = createStore(myReducer); // Creamos nuestro componente de react const counter = ({value, clickSumar, clickRestar}) => { <div> <h1>{value}</h1> <button onClick={clickSumar}>Sumar</button> <button onClick={clickRestar}>Restar</button> </div> }; // Renderizamos el componente. const render = () => { ReactDOM.render( <Counter value={store.getState()} clickSumar={ ()=> store.dispatch({type: 'sumar'}) } clickRestar={ ()=> store.dispatch({type: 'restar'}) } />, document.getElementById('MyAppContainer'); ); };