In my project, I got rid of classes and I'm just using Hooks. Now that I'm trying to create a HOC, my linter is returning an error for using Hooks inside my curry function. This is the simplified version of my code:
const myCurryFunction = WrappedComponent => props => {
const [state, setState] = React.useState();
return <WrappedComponent {...props} />
}
And the full eslint error is this one:
React Hook "useState" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.
Any clue? I'll really appreciate any advice
Two choices for you.
Respect the rules of hooks , make changes to your code.
const myCurryFunction = WrappedComponent => function Comp(props) { const [state, setState] = React.useState(); return }
I found this github issue: https://github.com/facebook/react/issues/20531
The HOC pattern should work, but is very specific.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.