Question
I found this library by looking for a way to enhance/improve the functionality of React.Context
So I have some questions about what not to do, best practice usage, etc.
- Is there a performance issue if I implement "helper" hooks similar to these:
export const useMainStoreState = <T extends keyof State>(resource: T) => {
return useContextSelector(context, (v) => v[0][resource]) as State[T];
};
export const useMainStoreDispatch = () => {
return useContextSelector(context, (v) => v[1]);
}
- Is there any performance issue if I setup/access
state and dispatch in "Object" instead of a "Tuple" ?
export const context = createContext<{ state: State, dispatch: Dispatch }>({ state: initialState, dispatch: () => null });
// then in component
const resource = useContextSelector(context, (v) => v.state.resource);
const dispatch = useContextSelector(context, (v) => v.dispatch);
// this may also be combined with the code on top about `useMainStore()`
Question
I found this library by looking for a way to enhance/improve the functionality of
React.ContextSo I have some questions about what not to do, best practice usage, etc.
stateanddispatchin "Object" instead of a "Tuple" ?