Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactDOM.render is no longer supported in React 18

I'm using rerender and renderHook from React-Testing-Library. Recently upgraded React version to 18 and now have below error in one of the test case.

Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot

rerender();
renderHook(() => abc());

Since I am not using render why the warning is pointing rerender and renderHook as render?

like image 960
John Avatar asked Oct 15 '25 02:10

John


1 Answers

instead of using "@testing-library/react-hooks" use "@testing-library/react"

import { renderHook, act } from "@testing-library/react";
like image 111
ALireza Bagheri Avatar answered Oct 17 '25 16:10

ALireza Bagheri



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!