[Docs] Improve `atomFamily` typings to be obvious to use
See original GitHub issueAs per https://github.com/pmndrs/jotai/discussions/433#discussion-3327022
It’s not currently 100% correct how atomFamily
typings are working now especially if you want to explicitly pass generic arguments to it.
For instance:
export const profitLossEngineAtom = atomFamily<
ProfitLossFamilyInitialize,
ProfitLossEngineState,
SetStateAction<ProfitLossEngineState>
>(
({ id }) => {
const anAtom = atom({ id, queries: {}, queryResult: {} });
anAtom.onMount = (setAtom) => {
setAtom({ id, queries: {}, queryResult: {} });
};
return anAtom;
},
(a, b) => a.id === b.id
);
If you pass third argument to be just ProfitLossEngineState
it will break typings for all the setters that would like to use a callback like setAtomState(it => ({ ...it, queries: { ... }}))
It’s a bit counterintuitive especially since it used to work just fine before.
To understand the problem better and get reproduces etc. read the discussion above.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Roadmap to v1 · Issue #333 · pmndrs/jotai - GitHub
#269 [Question] Can jotai be used without Suspense? [Docs] Improve atomFamily typings to be obvious to use # ...
Read more >atomFamily(options) - Recoil
Returns a function that returns a writeable RecoilState atom.
Read more >How to get all elements from an atomFamily in recoil?
You have to track all ids of the atomFamily to get all members of the family. Keep in mind that this is not...
Read more >Adding A Commenting System To A WYSIWYG Editor
In this article, we'll be re-using the foundational WYSIWYG Editor built in the first article to build a commenting system for a WYSIWYG ......
Read more >What happened to Components being just a visual thing?
I really like when Components are actually just visual components. Like the JSX specification indicated: // Using JSX to express UI components..
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
@HosseinAgha Thanks for chiming in. I will add some notes in docs.
https://github.com/pmndrs/website/pull/65#issuecomment-830792790