Code React Sweetly
/
Ref Hook
Ref Hook
https://leanpub.com/code-react-sweetly
How to Access a Function Component’s Ref
https://leanpub.com/code-react-sweetly
What Exactly Is the useRef() Function?
https://leanpub.com/code-react-sweetly
Syntax of the useRef() Hook
https://leanpub.com/code-react-sweetly
Example 1: Call the useRef Hook without an initialValue argument
https://leanpub.com/code-react-sweetly
Example 2: Call the useRef Hook with an initialValue argument
https://leanpub.com/code-react-sweetly
How to Access the Value Inside a Ref Object
https://leanpub.com/code-react-sweetly
How to use the dot notation to access a ref object’s value
https://leanpub.com/code-react-sweetly
Syntax
https://leanpub.com/code-react-sweetly
Example
https://leanpub.com/code-react-sweetly
How to use the square bracket notation to access a ref object’s value
https://leanpub.com/code-react-sweetly
How to Update the Value Inside a Ref Object
https://leanpub.com/code-react-sweetly
How to use the dot notation to update a ref object’s value
https://leanpub.com/code-react-sweetly
How to use the square bracket notation to update a ref object’s value
https://leanpub.com/code-react-sweetly
Important Things to Know About Accessing and Updating React Refs
https://leanpub.com/code-react-sweetly
Dot vs. square brackets notation
https://leanpub.com/code-react-sweetly
Never read or write a ref’s current property during rendering
https://leanpub.com/code-react-sweetly
React updates refs immediately
https://leanpub.com/code-react-sweetly
How to Use React Refs to Manage DOM Nodes
https://leanpub.com/code-react-sweetly
1. Declare a ref variable with
null
as the initial value
https://leanpub.com/code-react-sweetly
2. Assign the ref object as the value of your JSX element’s ref attribute
https://leanpub.com/code-react-sweetly
How Does React Ref Hook Work Behind the Scenes?
https://leanpub.com/code-react-sweetly
How Does Updating
ref.current
Affect the Ref Hook’s State Object?
https://leanpub.com/code-react-sweetly
1. Primitive data types are passed by value to variables
https://leanpub.com/code-react-sweetly
2. Non-primitive data types are passed by reference to variables
https://leanpub.com/code-react-sweetly
Up next
Variables vs. Refs vs. States
In this chapter
Ref Hook
How to Access a Function Component’s Ref
What Exactly Is the useRef() Function?
How to Access the Value Inside a Ref Object
How to Update the Value Inside a Ref Object
Important Things to Know About Accessing and Updating React Refs
How to Use React Refs to Manage DOM Nodes
How Does React Ref Hook Work Behind the Scenes?
How Does Updating ref.current Affect the Ref Hook’s State Object?