Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
IrvingArmenta opened this issue Sep 2, 2024 · 1 comment
Open

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

IrvingArmenta opened this issue Sep 2, 2024 · 1 comment

Comments

@IrvingArmenta
Copy link

IrvingArmenta commented Sep 2, 2024

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()` 
@dai-shi
Copy link
Owner

dai-shi commented Sep 2, 2024

1: No
2: No


As useContextSelector RFC is basically rejected, I would generally suggest the following.

This library exists as an internal library for React-Tracked and has been maintained. Its purpose is to make it compatible with Concurrent Rendering, but it's not often the capability people need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants