-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
useService logs warning about uninitialized service when service is passed to child component #1132
Comments
This behavior likely occurred in 4.8.x as well, can you check there? |
@davidkpiano Yes, checked all the way back to 4.7.0 where this issue begins. It was not present 4.6.7 and 4.7.0 RC's throw errors. |
@davidkpiano Is any work around for that ? I am trying to put the service in React Context and consume it after but I am getting the same error . |
Try updating to the latest |
@davidkpiano I am on "@xstate/react": "^0.8.1", and "xstate": "^4.9.1" and I am still getting the warning . I am getting the Interpreter from context but the useService is returning undefined so I can not use the machine . |
Does the app otherwise work fine? If so, you can ignore the warning for now. |
@davidkpiano My workaround is to pass into React context, [state,send] from UseMachine instead of the service . I can provide a code sandbox if you want. |
@davidkpiano in @xstate/react/v/1.0.0-rc.4 I have no problem . Is it safe to use the next version for production ? |
@davidkpiano Machine given to In versions before 1.0.0-rc.2 I am getting the service warning . Sandbox : https://codesandbox.io/s/great-herschel-9opwh?file=/src/App.js I guess its just a warning a not a bug ? |
@seloner Prefer this: const [state, send] = useMachine(counterMachine, {
context: someContext // initial context
}); |
@seloner the problem is that |
@Andarist I want to persist state also. I am getting no warning ,I guess its ok to do it like that ? |
This is now fixed in the latest |
Add React Router. @xstate/next fixes an issue where using the loginStateService from within a <Router> component threw an error. statelyai/xstate#1132
Description
In v4.7.0-4.9.0 a warning is logged to the console when calling
useService
on a service prop.Expected Result
No warning.
Actual Result
Warning: Attempted to read initial state from uninitialized service 'toggle'. Make sure the service is started first.
Reproduction
https://codesandbox.io/s/xstate-react-template-uninitialized-service-warning-cz351
Additional context
Note that the machine is created at the top of the application (App) and passed to a child (Child).
The text was updated successfully, but these errors were encountered: