Question on When the useAtom Overload Type is Triggered #2499
-
Hey guys, I've recently been trying to read and understand the code logic of Jotai. When I came across the overloading of //ref: https://github.com/pmndrs/jotai/blob/main/src/react/useAtom.ts#L42
export function useAtom<AtomType extends Atom<unknown>>(
atom: AtomType,
options?: Options,
): [Awaited<ExtractAtomValue<AtomType>>, never] Given that its second return value is const primitiveAtom = atom(0)
const readonlyDerivedAtom1 = atom(() => 0)
const readonlyDerivedAtom2 = atom((get) => get(primitiveAtom))
// Both of the above read-only atoms' corresponding useAtom type should be another overload
// ref: https://github.com/pmndrs/jotai/blob/main/src/react/useAtom.ts#L27
export function useAtom<Value>(
atom: Atom<Value>,
options?: Options,
): [Awaited<Value>, never] I've looked through the unit tests and seem to find no test code for this type of overload, so I'm curious about what kind of atom it specifically corresponds to. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
Beta Was this translation helpful? Give feedback.
-
I think if you remove the overload, some tests will fail. |
Beta Was this translation helpful? Give feedback.
Thanks for your investigation. It revealed that some tests are missing. #2503 adds it.