Skip to content

How to properly type the initialValues argument provided to useHydrateAtoms in a reusable TestProvider #2650

Answered by dai-shi
vtrofin asked this question in Q&A
Discussion options

You must be logged in to vote

I wanted to not use type assertion

I see. Then, Map might be a good solution.


How about this?

Repro: https://tsplay.dev/WyLXAm
A possible fix: https://tsplay.dev/W4gxvm

import type { PropsWithChildren, FunctionComponent } from "react";
import type { WritableAtom } from "jotai";
import { useHydrateAtoms } from "jotai/utils";

type AnyWritableAtom = WritableAtom<unknown, any[], unknown>;
export type InitialAtomValues = Array<readonly [AnyWritableAtom, unknown]>;

interface InitialProps extends PropsWithChildren {
  initialValues: InitialAtomValues;
}

const HydrateAtoms: FunctionComponent<InitialProps> = ({
  children,
  initialValues,
}) => {
  useHydrateAtoms(initialValues);

  return <>{

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@dai-shi
Comment options

@vtrofin
Comment options

@dai-shi
Comment options

Answer selected by vtrofin
@vtrofin
Comment options

@dai-shi
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants