This course has been updated! We now recommend you take the State Machines in JavaScript with XState, v2 course.

Check out a free preview of the full State Machines in JavaScript with XState course:
The "Refactoring with XState Solution" 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 live codes the solution to the refactoring with XState exercise.

Get Unlimited Access Now

Transcript from the "Refactoring with XState Solution" Lesson

>> Finishing up this exercise, we have the send, where we have currentState. So whenever we have a click events, we're going to send: 'CLICK'. And so inside of our send, we're updating the current state with machine.transition. And this is going to use Xstate instead of our own transition function in order to determine the next state.

[00:00:26] Then we're setting the data state attribute of eLBox to the currentState's value. And so if we go to Exercise 02, we're gonna see that it works the exact same way, with the difference that if we log out the currentState, We actually see an Xstate state object instead of just our string over here.