Replies: 8 comments 10 replies
-
Please always try to share a repro case in a runnable form - either by providing a git repository to clone or a codesandbox. OSS maintainers usually can't afford the time to set up the repro, even if exact steps are given. |
Beta Was this translation helpful? Give feedback.
-
Sure! The repo is https://github.com/pakoito/buildmancer/ and there's a build running at https://pakoito.github.io/buildmancer/ State machine Component using the Hook The repro steps are: After using |
Beta Was this translation helpful? Give feedback.
-
Video of the repro steps |
Beta Was this translation helpful? Give feedback.
-
For this particular case I believe you're better off adding a test for this use case, as it isn't covered by the current suite: https://github.com/statelyai/xstate/blob/main/packages/xstate-react/test/useMachine.test.tsx Worst case you prove me wrong and I have to go back and reassess what I'm doing wrong, and you leave with 1 additional test :D |
Beta Was this translation helpful? Give feedback.
-
This won't cause a rerender because the state doesn't change (transitions to self) and there is nothing in the state to indicate that the component should rerender (such as different state value, changed context, new actions...) One way to show the state as "changed" with a self-transition is to perform an action: WIN: { target: 'play', actions: 'someAction' } In general, this is an indication of something missing in your logic. Can you answer why you want this self-transition to cause a rerender? (Haven't had a chance to dive into the code) |
Beta Was this translation helpful? Give feedback.
-
Yep! I have a "Fight" scene, and once the player beats the enemy, a new "Fight" scene has to come up. The fight state is the payload of the event, as in which enemy you're fighting, resetting the player health, and other state changes. If this was Street Fighter it'd be changing "Ryu vs Ken in US" to "Ryu vs Sagat in Thailand". The characters and background change, but the scene is the same. I tried to put a
The third option is adding a non-transient state with a scene that says "Click to start the next fight", but I'd rather not modify the game design to accommodate this hahaha |
Beta Was this translation helpful? Give feedback.
-
It seems to work with the Action |
Beta Was this translation helpful? Give feedback.
-
Its not re rndering for me |
Beta Was this translation helpful? Give feedback.
-
I use the payload to make players go through different stages of an Arcade mode. Each stage has a new payload for the enemies. What I am finding is that transitioning from a "stage" to itself with a new payload isn't forcing a rerender, which means it doesn't transition to a new state.
I am sure I can make it work with an additional transient state, but I am also unable to force a re-render when that state has
always
clauses. The machine doesn't transition to the state after the transient. See #3245Beta Was this translation helpful? Give feedback.
All reactions