[Question] Is there any way to create a readonly focusAtom? And is it possible to make it work with atomWithImmer?
See original GitHub issueFor example here’s my atoms:
const pagesAtom = atom([{
children: ['element 1', 'element 2'],
}]);
const currentPageAtom = atom(0);
const currentPageElementsAtom = atom(get => get(pagesAtom)[get(currentPageAtom)].children);
const { index } = props;
const currentElementAtom = focusAtom(currentPageElementsAtom, optic => optic.nth(index)));
However since first parameter should be a WritableAtom so it doesn’t work. How about implementing something like focusAtomValue and updateFocusAtom to dress this issue?
Also I found that atoms created by atomWithImmer couldn’t be used by focusAtom. I can manually use immer to do the samething in the original atom, but is there a better way to do it?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Immer — Jotai, primitive and flexible state management for ...
In this bundle, we don't have read-only atoms, because the point of these functions is the immer produce(mutability) function.
Read more >Remote Programming Setup Using Atom - YouTube
Tutorial of how to setup remote development paradigm using PuTTY and Atom Editor on Windows environment.
Read more >Atomic Design with React & Typescript: a match made in heaven
Nathalia Rus joined at ReactJS Girls London Meetup to speak about Atomic Design with React & Typescript.
Read more >Cannot conditionally render nodes under root template - sycamore
Currently, if performing an if/else statement in the root of a template! invocation, an unhandled exception occurs. To Reproduce Steps to reproduce the...
Read more >Prevent Rerenders and Add Functionality with Jotai Write-only ...
They can receive a write function that will handle the updates to your atom state which will fix the rerender issue. We will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well, the code for #452 would actually be a few lines.
But, types, tests, and docs wouldn’t be trivial.
@dai-shi Well, I solved the readonly issue but not atomWithImmer one. I tried to dig a bit into it to see if I can create a PR, but it turned out that it’s a bit complicated than I thought. Hopefully someone else can work on it to make it more universal.