I am trying to use Context
and Reducers
via React\'s hooks, and running into problems with the order of the hooks not being constant. My understanding
Writing my comment as an answer:
The problem is that you're calling Event.Event()
directly, even though it is a react component. That causes react to treat the hook calls inside the function as part of Container
, even though you meant for them to be part of Event.
The solution is to use JSX:
return isTodays &&
Why this works is clearer when you replace the JSX with the resulting JS code:
return isTodays && React.createElement(Event.Event, { dayHeight, event: e })
See https://reactjs.org/docs/react-api.html#createelement. You never want to call the function components directly, how react works is that you always hand a reference the component to react and let it call the function at the correct time.