本文整理匯總了TypeScript中recompose.withStateHandlers函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript withStateHandlers函數的具體用法?TypeScript withStateHandlers怎麽用?TypeScript withStateHandlers使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了withStateHandlers函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: mapState
const localStorageContainer = <TState, TUpdaters extends StateHandlerMap<TState>, TOutter>(
mapState: (s: Storage) => TState,
mapHandlers: (s: Storage) => StateUpdaters<TOutter, TState, TUpdaters>,
) => {
const state = mapState(storage);
const handlers = mapHandlers(storage);
return withStateHandlers<TState, TUpdaters, TOutter>(state, handlers);
}
示例2:
import { withStateHandlers } from 'recompose';
interface State {
editableLabelError: string;
}
interface Handlers {
resetEditableLabel: () => State;
setEditableLabelError: (error: string) => State;
[key: string]: any;
}
export type EditableLabelProps = State & Handlers;
export default withStateHandlers<State, Handlers, { linodeLabel: string }>(
({ linodeLabel }) => ({
editableLabelError: ''
}),
{
resetEditableLabel: (state, { linodeLabel }) => () => ({
...state,
editableLabelError: ''
}),
setEditableLabelError: (state, ownProp) => errorText => ({
...state,
editableLabelError: errorText
})
}
);
示例3:
configDrawerOpen: false,
configDrawerError: undefined,
configDrawerSelected: undefined,
configDrawerAction: undefined
};
export type ConfigDrawerProps = State & Handlers;
export default withStateHandlers<State, Handlers & Record<string, any>>(
initialState,
{
openConfigDrawer: state => (_, action: (id: number) => void) => ({
...state,
configDrawerOpen: true,
configDrawerError: undefined,
configDrawerSelected: undefined,
configDrawerAction: action
}),
closeConfigDrawer: state => () => ({
...state,
configDrawerOpen: false
}),
configDrawerSelectConfig: state => (id: number) => ({
...state,
configDrawerSelected: id
})
}
);
示例4: withStateAndHandlers
*
* return (<div>Hello world!</div>)
* }
*/
const withStateAndHandlers = withStateHandlers<
LoadingAndErrorState,
StateAndStateUpdaters,
{}
>(
{
loading: false,
error: undefined
},
{
setLoadingAndClearErrors: () => () => ({
loading: true,
error: undefined
}),
setErrorAndClearLoading: () => (error: string) => ({
loading: false,
error
}),
clearLoadingAndErrors: () => () => ({
loading: false,
error: undefined
})
}
);
const withLoadingAndError = (Component: any) =>
withStateAndHandlers(Component);
示例5:
[key: string]: any;
}
export type MutationDrawerProps = State & Handlers;
export default withStateHandlers<State, Handlers>(
ownProps => ({
mutationDrawerError: '',
mutationDrawerLoading: false,
mutationDrawerOpen: false
}),
{
openMutationDrawer: state => () => ({
mutationDrawerError: '',
mutationDrawerLoading: false,
mutationDrawerOpen: true
}),
closeMutationDrawer: state => () => ({
...state,
mutationDrawerOpen: false
}),
mutationFailed: state => (error: string) => ({
mutationDrawerError: error,
mutationDrawerLoading: false,
mutationDrawerOpen: true
})
}
);