Skip to content

Instantly share code, notes, and snippets.

@cyb3rsalih
Last active May 12, 2019 14:13
Show Gist options
  • Save cyb3rsalih/f5100588933e7bd9da7d1c82068ca984 to your computer and use it in GitHub Desktop.
Save cyb3rsalih/f5100588933e7bd9da7d1c82068ca984 to your computer and use it in GitHub Desktop.
Redux-5
import React from 'react';
import ReactDOM from 'react-dom';
import './css/index.css';
import App from './pages/App';
import {BrowserRouter as Router } from 'react-router-dom'
import { createStore } from 'redux'
function reducer(state, action){
if(action.type == 'CHANGE_STATE'){
return action.payload
}
else{
return 'My State'
}
}
const store = createStore(reducer)
const action = {
type: 'CHANGE_STATE',
payload: 'My New State'
}
console.log(store.getState()) // Before Dispatch
store.dispatch(action)
console.log(store.getState()) // After Dispatch
ReactDOM.render(<Router> <App/> </Router> , document.getElementById('root'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment