You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Found out how.
It boils down to the different node types that are used in React.
There are Elements, Components (Function- and Class-) and this library throws Builders into the mix. Hooks (useState, etc.) work only in Function Components.
In order to use hooks in njsx you need to:
Define a function with a single input ("props") that returns a ReactElement.
It cannot return a Builder. If you use Builders, don't forget the () at the end. Inside this function you may use hooks.
wrap that function using njsx(MyFuncComponent)
However I feel all this is cumbersome and goes against the "compositional" spirit of njsx.
IMO it's better to avoid hooks altogether when using njsx and use other means of state management.
React's hook functions do not like to be called from within
Builder
s.I tried to mitigate this by eagerly instantiating
ReactElement
s by appending()
s to builders everywhere, but to no avail.The text was updated successfully, but these errors were encountered: