Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get return value from renderHook

I got a custom hook which return a function

export function useMyCustomHook = (dispatch) => () => {... some things with dispatching to store };

I'm trying to use the return value like this in a jest test:

  const result = renderHook(() => useMyCustomHook(useDispatch()));
  console.log(result.current);

but result.current is undefined. So how can I actually get the return value?

like image 972
Yonatan Nir Avatar asked May 19 '26 15:05

Yonatan Nir


1 Answers

According to react-hooks-testing-library renderHook returns an object with result, so to access it:

const { result } = renderHook(() => useMyCustomHook(useDispatch()));
console.log(result.current);
like image 119
Jose Felix Avatar answered May 21 '26 04:05

Jose Felix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!