如何从 renderHook 获取 return 值
How to get return value from renderHook
我有一个自定义挂钩,其中 return 一个函数
export function useMyCustomHook = (dispatch) => () => {... some things with dispatching to store };
我正在尝试在玩笑测试中使用这样的 return 值:
const result = renderHook(() => useMyCustomHook(useDispatch()));
console.log(result.current);
但 result.current
未定义。那么我怎样才能真正获得 return 值呢?
根据 react-hooks-testing-library renderHook
returns 一个带有结果的对象,因此要访问它:
const { result } = renderHook(() => useMyCustomHook(useDispatch()));
console.log(result.current);
我有一个自定义挂钩,其中 return 一个函数
export function useMyCustomHook = (dispatch) => () => {... some things with dispatching to store };
我正在尝试在玩笑测试中使用这样的 return 值:
const result = renderHook(() => useMyCustomHook(useDispatch()));
console.log(result.current);
但 result.current
未定义。那么我怎样才能真正获得 return 值呢?
根据 react-hooks-testing-library renderHook
returns 一个带有结果的对象,因此要访问它:
const { result } = renderHook(() => useMyCustomHook(useDispatch()));
console.log(result.current);