'Getting data attribute from root in ReactJs
I'm trying to grab the attribute listed in the div being rendered but it returns undefined. Any idea on how to go about it will be greatly appreciated
index.html
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root" data-username="mark"></div>
</body>
index.js
const root = ReactDOM.createRoot(document.getElementById("root"));
if (root) {
console.log(root.dataset)
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
