Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error when passing root prop to RecoilizeDebugger #138

Open
matiasmm opened this issue May 3, 2021 · 4 comments
Open

Typescript error when passing root prop to RecoilizeDebugger #138

matiasmm opened this issue May 3, 2021 · 4 comments

Comments

@matiasmm
Copy link

matiasmm commented May 3, 2021

Having problems setting up Recoilize in a Next.js app and typescript.

I get:
Type '{ root: any; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; }'. on this line:

      <RecoilizeDebugger root={root} />

The problem seems to be we are initiating root as null in this line:

 const [root, setRoot] = React.useState(null)

Here is the complete code: https://gist.github.com/matiasmm/1d87a1221e14345b1153d296e25e4bbc#file-_app-tsx-L27

Is there a workaround for this?

@samihamine
Copy link
Contributor

Same problem here, any help please?

@safethecode
Copy link

safethecode commented Oct 7, 2021

Do you want to try it like this?

  const [root, setRoot] = useState<HTMLElement>();

  const RecoilizeDebugger = dynamic(
    () => {
      return import('recoilize');
    },
    { ssr: false },
  );

  useEffect(() => {
    if (typeof window.document !== 'undefined') {
      setRoot(document.getElementById('__next') as HTMLElement);
    }
  }, [root]);

@imsukmin
Copy link

I fixed this error temporary. do typing in dyanmic dynamic<{root: HTMLElement | undefined}>

  const [root, setRoot] = useState<HTMLElement>()
  const RecoilizeDebugger = dynamic<{root: HTMLElement | undefined}>(
    () => import('recoilize'),
    {ssr: false},
  )

  useEffect(() => {
    if (typeof window.document !== 'undefined') {
      setRoot(document.querySelector('#__next') as HTMLElement)
    }
  }, [root])

@huraim
Copy link

huraim commented May 27, 2023

This issue occurs when the root is not defined and the RecoilateDebugger is running
Do you want to try it like this?

{root !== undefined && <RecoilizeDebugger root={root} />}
  const [root, setRoot] = useState<HTMLElement | undefined>();
  const RecoilizeDebugger = dynamic<{ root: HTMLElement | undefined }>(() => import('recoilize'), {
    ssr: false,
  });

  useEffect(() => {
    if (typeof window.document !== 'undefined') {
      setRoot(document.getElementById('__next') as HTMLElement);
    }
  }, [root]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants