-
-
Notifications
You must be signed in to change notification settings - Fork 622
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
How to avoid extra rerender? #26
Comments
Hi, thanks for opening up the issue. const editIdAtom = atom<number | null>(null);
const setEditIdAtom = atom(null, (_get, set, x: number) => set(editIdAtom, x));
const [,setEditId] = useAtom(setEditIdAtom); Now, I wonder if we can build a generalized hook. const useSetAtom = (anAtom) => {
const writeOnlyAtom = useMemo(() => atom(null, (get, set, x) => set(anAtom, x)), [anAtom]);
return useAtom(writeOnlyAtom)[1];
}; |
I think a set of utility hooks for common patterns (like the one mentioned above) would add that icing on top of a wonderful cake |
@cevr Yeah, I agree. And, I want to separate them from the core. Let me start with this one. The utility hooks can get big. I need someone to volunteer to help it, especially for documentation & examples. |
https://www.npmjs.com/package/jotai/v/0.5.0 published which includes #35 |
I have two questions about this part of the code:
@dai-shi Looking forward to your reply |
I don't know why you think it doesn't avoid extra rerenders, but here's the example: |
@dai-shi |
@dai-shi |
is there any different between |
No. 😁 Line 2 in 8480207
|
with Jotai, the
<FakeCard />
will re-render whenever editId changed, but Recoil.js does not because i can select only setter function. How to achieve the same behavior with Jotai?Recoil
Jotai
The text was updated successfully, but these errors were encountered: