The State component is the most generic component possible, exposing to the children function the state and setState, wrapped in a classic React.Component class.
import { State } from 'react-powerplug'
<State initial={{ isLoading: false, data: null }}>
{({ state, setState }) => {
const onStart = data => setState({ isLoading: true })
const onFinish = data => setState({ data, isLoading: false })
return (
<DataReceiver data={state.data} onStart={onStart} onFinish={onFinish} />
)
}}
</State>
initial = {} (optional)
Specifies the initial state, must be an object.
By default, the initial state is an empty object.
onChange (optional)
The onChange event of the State is called whenever the state changes.
TL;DR: { state, setState }
state
object
Your state
setState
(object | (state: object) => object) => void
State setter. Is the setState from React.Component.