A
A
asmut2020-09-15 18:27:29
React
asmut, 2020-09-15 18:27:29

How to use document.querySelector in React?

Good afternoon gentlemen and ladies.

Entering React.
I want to implement a shift (movement).

What I do:
const hr = document.querySelector('#hr'); //**error here immediately
hr.style.transform = 'rotateZ(${(hh) + (mm/12)}deg)';

I get: hr is null

Perhaps the whole approach is wrong.
The first thing that interests me: document.querySelector - how to use it in React, and is it right to do it that way?
Second: is it right to change transform just like this?

Thanks in advance for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
8
8XL, 2020-09-15
@asmut

They say that this is generally a bad tone in react (in the worst case, there are refs), but I could be wrong.
Regarding querySelector https://ru.reactjs.org/docs/react-without-jsx.html , read about your question here.
querySelector: read about refs, they are more about react and jsx.
Transform changes The element you are changing . <div style={{transform : `rotateZ(${hh...}deg)`>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question