Last active
April 19, 2017 13:47
-
-
Save maplemap/25b69a4c1c29117c655df2fa17d3f482 to your computer and use it in GitHub Desktop.
React Middleware
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 { createStore, applyMiddleware } from 'redux' | |
import Counter from './components/Counter' | |
import counter from './reducers' | |
const customMiddleWare = store => next => action => { | |
console.log("Middleware triggered:", action); | |
next(action); | |
} | |
const store = createStore(counter, | |
applyMiddleware(customMiddleWare) | |
); | |
const rootEl = document.getElementById('root') | |
const render = () => ReactDOM.render( | |
<Counter | |
value={store.getState()} | |
onIncrement={() => store.dispatch({ type: 'INCREMENT' })} | |
onDecrement={() => store.dispatch({ type: 'DECREMENT' })} | |
/>, | |
rootEl | |
) | |
render() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment