koordinates / xstate-tree

Build UIs with Actors using xstate and React
MIT License
85 stars 6 forks source link

perf(actions): do not re-create actions object #25

Closed UberMouse closed 1 year ago

UberMouse commented 1 year ago

This behaviour caused problems if one of the action functions was used in something like a React useEffect. Since the reference to the function changes every time the machine state changes.

This could lead to an infinite loop.

Instead pass a proxy that references the latest selector values to the actions function. This way it can be created only once when the machines view is first rendered

Fixes Improve action handling #2

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 2.0.11 :tada:

The release is available on:

Your semantic-release bot :package::rocket: