question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Docs] Improve `atomFamily` typings to be obvious to use

See original GitHub issue

As 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:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dai-shicommented, May 1, 2021

@HosseinAgha Thanks for chiming in. I will add some notes in docs.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found