Sign in
Log inSign up

How to mock React Hooks?

Deactivated User's photo
Deactivated User
·Feb 19, 2019

The latest version of React introduces Hooks. Some 3rd-party libraries already provide hooks as an alternative to HOCs, e.g. the translation library react-i18next.

Mocking some functionality is easy using higher order components, we just can export the main component (without the HOC) and pass a mocked function to the props. Is there a generic way (provided by React) how hooks can be mocked?

Some hooks like useState are an important part of the component and there's no need to mock them, but I would like to mock other hooks (e.g. translation or redux if they provide a hook in a future release).

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct