Skip to content

Questions about "best practices" or NOT to do's #134

@IrvingArmenta

Description

@IrvingArmenta

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.

  1. 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]);
}
  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()` 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions