As of now, hooks have some problems with testability and debugging. The state of a hook can't be tracked with a debugger on component instance as it's done with class components, this is possible only with React dev tools. Enzyme doesn't fully support hooks yet. Hooks may be harder to mock or spy than component lifecycle methods because this can't be done on component instance.
Hooks have several inherent problems that sometimes need to be addressed in counterintuitive and overly complicated ways.
There are well-known problems with useEffect
and useLayoutEffect
function scopes that don't work well with setTimeout, events and other kinds of callback-based APIs (workarounds are described in this answer).
That there's no counterpart to shouldComponentUpdate
may result in component nesting to prevent unnecessary updates. This especially applies to useContext
. If there's a need to prevent updates, this isn't much better than context Consumer
and requires to use nested component:
const WrapperWithConsumer = () => {
return <FooContext.Consumer>
{({ foo }) => <PureWrappedComponent foo={foo}/>}
</FooContext.Consumer>;
}
const WrapperWithHook = () => {
const { foo } = useContext(FooContext);
return <PureWrappedComponent foo={foo}/>
}
As any other recent API, hooks restrict a project to be used with up-to-date React version, prevent its components from being reused in older projects and take away the opportunity to switch to alternative implementations - Preact, Inferno, etc.