avaragado / xstateful-react

Use xstateful with React, accessing states and activities from multiple statecharts anywhere in your app
MIT License
30 stars 2 forks source link

Machine.State always renders child functions #4

Closed ShMcK closed 5 years ago

ShMcK commented 5 years ago

Child functions appear to not listen to the is/not condition.

<Machine.State  is="SomeState">
  {(props) => (
     <div>Always renders regardless of condition</div>
  )}
</Machine.State>

<Machine.State  is="SomeState" render={(props) => (
  <div>conditionally renders as expected</div>
)} />
avaragado commented 5 years ago

This is by design, to closely match the behaviour of react-router (see https://reacttraining.com/react-router/web/api/Route). With children functions, there's an extra prop match with the result of the condition.

See https://github.com/avaragado/xstateful-react#machine for the rules followed for the component, render and children props.