Skip to content

What is the equivalent of useRef in Leptos? #880

Answered by gbj
bluenote10 asked this question in Q&A
Discussion options

You must be logged in to vote

So it's important to start with the question, "Why on earth does React have useRef anyway?" In other words, why useRef instead of a normal variable?

I'm not a React expert by any means, by as I understand it, the reason React needs useRef is that the body of the component function runs over and over again whenever state is changed. This means that anything stored in a normal let or const variable inside the body of the component function is created again and again. useRef exists to tell React "no, don't create this object again, actually looked in your collection of stored stable references and use the thing you created the first time you rendered this function."

Leptos doesn't have this …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by bluenote10
Comment options

You must be logged in to vote
1 reply
@gbj
Comment options

gbj Apr 19, 2023
Maintainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants