Created
November 1, 2020 01:32
-
-
Save neomatrixcode/1d00b447c3e6c17dccd8bd804aef4ca2 to your computer and use it in GitHub Desktop.
This file contains 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 ReactDOM from 'react-dom'; | |
import './index.css'; | |
import App from './App'; | |
import reportWebVitals from './reportWebVitals'; | |
import { createStore } from 'redux' | |
import rootReducer from './reducers' | |
// Creamos el store al pasar el reducer raiz | |
const store = createStore(rootReducer) | |
// Mostramos el estado inicial | |
console.log(store.getState()) | |
// Cada vez que el estado cambie, lo mostramos | |
// Tenga en cuenta que subscribe() devuelve una función para anular el registro del listener | |
let unsubscribe = store.subscribe(() => | |
console.log(store.getState()) | |
) | |
let nextTodoId = 0 | |
// Enviamos algunas acciones | |
store.dispatch({ type: "AGREGAR_TAREA", id:nextTodoId++ ,text: "Tarea 1"}); | |
store.dispatch({ type: "AGREGAR_TAREA", id:nextTodoId++ ,text: "Tarea 2"}); | |
// Anulamos el monitoreo de las actualizaciones al estado | |
unsubscribe() | |
ReactDOM.render( | |
<React.StrictMode> | |
<App /> | |
</React.StrictMode>, | |
document.getElementById('root') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment