Minimal Redux Setup

let children = Children.map(this.props.children, child => 
cloneElement(child, {
…this.props,
…this.state,
setState: payload => this.setState(payload)
})
})
function reducer (state = init, action) {
switch (action.type) {
case 'UPDATE':
return {
...state,
...action.payload,
}
}
}
import { createStore } from 'redux'let init = { /* stuff */ }function reducer (state = init, action) {
switch (action.type) {
case 'UPDATE':
return {
...state,
...action.payload,
}
}
return state
}
function update (payload) {
return {
type: 'UPDATE',
payload,
}
}
let store = createStore(reducer)export { store, update }
import { connect } from 'react-redux'
import { update } from './store'
export default
connect(state => state)(
({ dispatch, state }) =>
<div>
<h1>{state.title}</h1>
<button
onClick={e => dispatch(update({ title: 'so minimal!' }))}
>
Give'r
</button>
</div>
)

--

--

Developer, Musician, Cook, Husband, Brother, Son

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store