A Redux-like API for creating stateful container components without the need to spin up or manage a store, subscriptions, or anything else.
import createRenderProps from './utils/createRenderProps'
import createReducer from './utils/createReducer'
import createStateSubscriber from './utils/createStateSubscriber'
export const LOADING = 'LOADING'
export const LOADED = 'LOADED'
export const actions = {
setLoading: () => ({
type: LOADING,
}),
setLoaded: () => ({
type: LOADED,
}),
}
export const initialState = false
export const reducerActions = {
[LOADING]: () => true,
[LOADED]: () => initialState,
}
export const isLoadingReducer = (
createReducer(
reducerActions,
initialState,
)
)
const namespacedReducers = {
isLoading: isLoadingReducer,
}
const LoadingState = (
createStateSubscriber(
createRenderProps({
actions,
namespacedReducers,
})
)
)
export default LoadingState