'React Confirm Alert library showing "Warning: ReactDOM.render is no longer supported in React 18."
I'm trying to use the react-confirm-alert library for a confirmation dialog. But it's giving me a warning when the confirmation pop-up is opening for the react version upgrade. "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." Is there any way to get rid of the warning? Or is there any good alternative library that I can use for a confirmation dialog?
Thank you!
Solution 1:[1]
Probably your answer must be:
Try this in your index file:
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
const rootElement = document.getElementById("root");
const root = ReactDOM.createRoot(rootElement);
root.render(
<App />
);
This works in latest react version.
Solution 2:[2]
Try this:
import ReactDOM from 'react-dom/client';
then
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
It will work
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Atul Yadav |
Solution 2 | Andronicus |