DEV Community

loading...

Discussion on: React Hooks (useContext, useEffect, useState, useRef) Summarized Like Crazy (Short & Concise Article).

Collapse
vnankov profile image
Valentin Nankov

Thank you very much for the clarification! So in other words useRef is like querrySelector function in the pure JS way. Please correct me if I am wrong.

Thread Thread
ishakmohmed profile image
Mohmed Ishak Author

You're right. Not to worry, usually you don't need it.

Thread Thread
moustachedsign profile image
Moustache Design

yes, the difference is querySelector is imperative, useRef declarative, also querySelector does a search for the string you pass to it, so you have to know that is unique and won't change.
useRef on the other hand, ties itself to that jsx element and nothing else.

Thread Thread
ishakmohmed profile image
Mohmed Ishak Author

Cool!