Fork me on GitHub
#reagent
<
2019-06-14
>
Michael Mackenzie22:06:58

has anyone had problems using react JS libraries that use the new hooks feature with reagent?

Michael Mackenzie22:06:56

i am completely stuck trying to get react-dnd (https://github.com/react-dnd/react-dnd) working with reagent

Michael Mackenzie22:06:20

calling a hook from the body of a render function (which i have verified is evaluating during a render) gives the following error:

Uncaught Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See  for tips about how to debug and fix this problem.
    at invariant ()
    at Object.throwInvalidHookError ()
    at Object.useRef ()
    at Object.exports.useDrag ()
    at Constructor.getfluentspanish$exercises$matching$item [as reagentRender] ()
    at 
    at Object.reagent$impl$component$wrap_render [as wrap_render] ()
    at Object.reagent$impl$component$do_render [as do_render] ()
    at 
    at Object.reagent$ratom$in_context [as in_context] ()

lilactown04:06:12

reagent components get turned into classes

lilactown04:06:42

so you cannot call a hook from inside a Reagent render function

😢 8
lilactown04:06:21

Notice the error says that Hooks can only be used inside function components

Michael Mackenzie13:06:58

So any libraries that call hooks are unusable from reagent?

Michael Mackenzie14:06:11

need to use :> to use the function as a react component, and wrap the response with as-element

Michael Mackenzie14:06:37

@U4YGF4NGM Thank you very much for explaining the thing about reagent components turning into classes. That pointed me in the right direction to find the solution

Michael Mackenzie22:06:42

i cannot find any evidence that there is more than one copy of react in the app

Michael Mackenzie22:06:08

this is like the third time i've had to rewrite this feature i'm working on due to limitations of drag-and-drop in reagent