jeudi 4 juillet 2019

Issue Testing react-native with useCallback

I'm setting up tests for a react-native app. I'm using react-native-testing-library and redux.

But i'm hitting a problem.

When the redux state got updated, inside my render test function, the component is re-rendered as expected but the useCallback deps doesn't seems to be updated !

As deps are not updated inside useCallbacks Hooks, my tests fails....

export const ListComponent = () => {
  const data = useSelector(myDataSelector);
  const onEndReached = useCallback(() => {
    if(data && data.length){
      // Do something
    }
  }, [data]);
  return <List />
}

Running this on a device or a simulator works well, data get updates inside useCallback.

But with test, data is not updated...

Need some help here ...

Thanks

Aucun commentaire:

Enregistrer un commentaire