Skip to content
Advertisement

React Using useState/Hooks In HOC Causes Error “Hooks can only be called inside of the body of a function component”

Is it not allowed to use hooks inside of a Higher Order Component? When I try to do it with this simple pattern I’m getting the error Invalid hook call. Hooks can only be called inside of the body of a function component.

JavaScript

Advertisement

Answer

I believe you should use the hooks inside the HOC:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement