StoreApiConstructor
This is just a type to represent the constructor of a class that extends StoreApi
. This constructor is a StateContainer so it can be passed directly to createContext()
.
Definition
interface StoreApiConstructor<TState> {
new (): StoreApi<TState>
actors?: { [key: string]: Actor }
selectors?: { [key: string]: Selector }
}
actors – optional object containing valid actors. Can contain nested actor maps.
selectors – optional object containing valid selectors. Can contain nested selector maps.
See the Actor and Selector types from Zedux.
Examples
We could set these properties literally on the constructor:
import { StoreApi } from 'react-zedux'
import { createStore } from 'zedux'
class CounterApi extends StoreApi {
store = createStore().hydrate(0)
}
CounterApi.actors = {
increment: () => state => state + 1
}
Or just use the static
keyword:
import { StoreApi } from 'react-zedux'
import { createStore } from 'zedux'
class CounterApi extends StoreApi {
static actors = {
increment: () => state => state + 1
}
store = createStore().hydrate(0)
}
Notes
See the StoreApi documentation for examples of how the actors and selectors are bound to the store.