Skip to content

Instantly share code, notes, and snippets.

@maplemap
Last active April 19, 2017 13:47
Show Gist options
  • Save maplemap/25b69a4c1c29117c655df2fa17d3f482 to your computer and use it in GitHub Desktop.
Save maplemap/25b69a4c1c29117c655df2fa17d3f482 to your computer and use it in GitHub Desktop.
React Middleware
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