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

useInterpret logs warning about uninitialized service when service is passed to child component #2157

Closed
anonymouscatcher opened this issue Apr 28, 2021 · 4 comments

Comments

@anonymouscatcher
Copy link

Description
Trying to use a machine using useInterpret but cannot access to machine in children and it throws error + a warning Attempted to read state from uninitialized service.

Expected Result

Actual Result

Reproduction
I think this is fixed in useMachine #1132 (comment)

Additional context

 "xstate": "^4.18.0",
  "@xstate/react": "^1.3.2",
@anonymouscatcher
Copy link
Author

Example:

  const selectService = useInterpret(
    selectMachine(props.data, false)
  );

 return (
    <>
      <Header
        selectService={selectService}
      />
      <TrackList
        itemProps={{ selectService }}
        {...props}
      />
    </>
  );

@anonymouscatcher
Copy link
Author

The weird thing about this issue is, Only Header has issue with it, TrackList component is working fine but at the end they use same component so what I guess is, it's has something todo with scheduling or something since I tried something stupid I rendered the Header with a setTimout(0) (with wrapping it with <Delay/> component) delay and then it worked correctly.

@stevenmusumeche
Copy link

I'm having the same issue.

@davidkpiano
Copy link
Member

This should no longer be an issue in the latest @xstate/react version, but please re-open if it is.

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

No branches or pull requests

3 participants