Releases: acdlite/recompose
withState() callback
Adds a second parameter to withState()
's state updating function — a callback that will be executed once the update is completed and the component is re-rendered. This simply exposes the feature by React's setState()
. https://facebook.github.io/react/docs/component-api.html#setstate
Also fixes an issue where defaultProps()
did not override props with values of undefined
.
withReducer() and flattenProps()
withReducer()
withReducer<T, U>(
stateName: string,
dispatchName, string,
reducer: (state: T, action: U) => T,
initialState: T,
BaseComponent: Class<ReactComponent>
): Class<ReactComponent>
Similar to withState()
, but state updates are applied using a reducer function. A reducer is a function that receives a state and an action, and returns a new state.
Passes two additional props to the base component: a state value, and a dispatch method. The dispatch method sends an action to the reducer, and the new state is applied.
This allows enables you to use Redux-style reducer logic at the component-level.
flattenProp()
renameProps(
propName: string,
baseComponent: Class<ReactComponent>
): Class<ReactComponent>
Flattens an prop so that its fields are spread out into the props object.
const Abc = compose(
withProps({
object: { a: 'a', b: 'b' },
c: 'c'
}),
flattenProp('object')
)(BaseComponent);
// Base component receives props: { a: 'a', b: 'b', c: 'c' }
This can be useful when using withState()
or withReducer()
and your state value is an object.