testing-library/testing-library-docs

react-testing-library/api: renderHook might be exported by `@testing-library/react-hooks`

achinchen opened this issue · 1 comments

Hello, maintainers.

I found the example code about renderHooks might can be updated, the current version is copied from react-testing-library/api.

If PR is needed, I'm happy to do for it.

Current

import {renderHook} from '@testing-library/react' 
// should be `import {renderHook} from '@testing-library/react-hooks'`

test('returns logged in user', () => {
  const {result} = renderHook(() => useLoggedInUser())
  expect(result.current).toEqual({name: 'Alice'})
})

Hi @achinchen, thanks for opening this.

The renderHook function moved from RHTL to RTL as part of the RTL work to support React 18.
RHTL has been deprecated and will only work for React<18. For React>18, you'll need to import from RTL.