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.
My name is Kent C. Dodds and I'm a Remix Co-Founder, JavaScript engineer, and teacher. I'm also active in the open source community. I like my family, JavaScript, and React.
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.
Oh man, have I got good news for you: testing-library.com/docs/native-te...