Under my root div react creates another div "automatically". Is there a way to add a class to that div? I need to add height: 100% to it to prevent the background content to scroll in mobile when an overlay is shown.
This is how it is shown when i inspect the element on the site. I need to add height:100% to the data-reactroot div when a button is clicked. But that div is nowhere in my source code.
<div id="root"> <div data-reactroot data-reactid="1" data-react-checksum="161698...
I could add this code in the container's componentDidMount()
let root = document.querySelectorAll('[data-reactroot]')[0]; if (root) { root.style.height = '100%'; }
But isnt there a better way to do it? This feels like kind of hacky (in a bad way)
To change the style of an element on click in React:Set the onClick prop on the element. When the element is clicked, set the active state. Use a ternary operator to conditionally set the new styles based on the state variable.
React doesn't do stylingReact components output HTML, and CSS styles the HTML. As far as the browser is concerned, React doesn't figure into it. The browser applies CSS rules to the HTML on the page, whether that HTML came from an . html file or was generated by React.
The equivalent of the document. getElementById() method in React is using refs. To select an element, set the ref prop on it to the return value of calling the useRef() hook and access the dom element using the current property on the ref , e.g. ref. current .
React developers build web applications or use React Native to develop mobile apps on the client-side of development. This requires the use of core front-end technologies like JavaScript, HTML, and CSS.
#root > [data-reactroot] { height: 100% }
in your CSS should work.
Or just the tag itself:
[data-reactroot] { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With