DEV Community

Discussion on: What's hard about React Hooks for you?

Collapse
 
hoverbaum profile image
Hendrik

The hardest part for us has been a difficulting in structuring components around state management and testability.

Components with hooks make testing super hard for us (in a React Native context). We can not use mounting for testing, as we are in react native, and shallowly rendering a component does not run anything inside a useEffect hook.

Thus we had to resort to mocking our useEffect to test our code which is super fragile since it basically mocks out react itself.

Our best option seem to be to go for custom hooks only which we can mock out easily for component testing and mock useEffect for those. But that just leads to weird code where instead of gaining colocation and readability from hooks we get messiness.

So, we are largely sticking to classes. Little though we want to.

Collapse
 
kentcdodds profile image
Kent C. Dodds • Edited

Oh man, have I got good news for you: testing-library.com/docs/native-te...