How we used to set a variable in assembly language:
mov [foo], ax
How we do it in React / Redux // constants.js
export const SET_FOO = 'SET_FOO'
// actions.js
import { SET_FOO } from './constants'
export const setFoo = foo => ({ type: SET_FOO, payload: foo })
// reducer.js
import { SET_FOO } from './constants'
const initialState = { foo: 0 }
const reducer = (state = initialState, action) => {
const { type, payload } = action
switch (type) {
case SET_FOO:
return { ...state, foo: payload }
default:
return state
}
export default reducer
// Component.js
import { connect } from 'react-redux'
import { setFoo } from './actions'
class Component extends React.Component {
handleSetFoo = foo => {
this.props.dispatch(setFoo(foo))
}
}
export default connect()(Component)
I don't understand how people don't see something is horribly wrong.