Check out a free preview of the full State Machines in JavaScript with XState course:
The "React and XState Q&A" Lesson is part of the full, State Machines in JavaScript with XState course featured in this preview video. Here's what you'd learn in this lesson:

David answers questions from the audience about using a service with React and XState, and about statecharts and its modeling of complexity.

Get Unlimited Access Now

Transcript from the "React and XState Q&A" Lesson

>> Alright, so Anwar asks a React specific question, if you use the use machine hook and you want to avoid passing down the props to the descendants, is it okay to put them in context? So you could put a service in context and it's never gonna cause any updates.

[00:00:15] And it's gonna do so for one reason and that's because the service never changes. You could subscribe to a service to get its data updates, but the service instance itself will never change. So, there is an example over here if you go to recipes and react, actually we have to go to Packages, xstate/react.

[00:00:40] And if you go to Services, There is this well I guess it's not here, useService, there it is. There is a useService hook, so you could grab that service from context, and then use that service just like you would use a machine. And because that service never changes, even as state is updated multiple times, it's completely performance to use that service in context, grab it, and then call this use service.

[00:01:12] So to get both the state, and the Send method