dev-resources.site
for different kinds of informations.
Multiple item using one ref
Published at
8/1/2022
Categories
react
useref
Author
yensubldg
Author
9 person written this
yensubldg
open
Some cases in ReactJS, we need use a variable declared by useRef
for items, components, ....
How to use
First, you need variable declared by useRef
and
and set initialValue to be an empty array []
const exampleRef = useRef([]);
Create a function to add item, component to exampleRef
const addToRefs = el => {
if (el && !exampleRef.current.includes(el)) {
exampleRef.current.push(el);
}
};
Then you just add ref
to item, component, ...
<div ref={addToRefs}>
</div>
Now, exampleRef.current
as an array, you can use methods with array to use for exampleRef
like map, forEach, ...
useref Article's
29 articles in total
How to create components interfaces using useRef/forwardRef/useImperativeHandle
read article
Hooks Behind The Scenes 3, UseRef!!!
read article
Mastering React's useRef Hook: Working with DOM and Mutable Values
read article
Understanding useRef: A Beginners Guide
read article
useRef Hook Explained
read article
useRef() in React . . .
read article
React State Management: When & Where add your states?
read article
Unlocking the Power of useRef: Besic to Advanced Examples for React Developers
read article
Leveraging useRef in TypeScript for Efficient DOM Manipulation
read article
Unlocking the Power of React Hooks
read article
React.useRefの理解を含めるエクササイズ
read article
Mastering React's useRef Hook: A Deep Dive
read article
Unlocking the Power of useRef in React: 12 Essential Use Cases
read article
Série React Hooks: useRef
read article
Toggle Password Visibility Using React useRef
read article
Stop using useState for everything
read article
Using React hooks to develop a Video Player
read article
React - How to load a form with the latest data
read article
React: сфокусировать поле ввода по чекбоксу
read article
How do I check/uncheck all checkboxes with a button In React Js using useRef() Hook ?
read article
Multiple item using one ref
currently reading
Closures and useEffects
read article
I need help. TypeError: Cannot read properties of undefined (reading 'current')
read article
Using React useRef Hook to access immediate past props or state.
read article
Compare Props in React Functional Components.
read article
Creating infinitely scrolling SPA using React
read article
useRef()가 순수 자바스크립트 객체라는 의미를 곱씹어보기
read article
Complete useRef() hook with live code examples
read article
Useful Patterns with React hooks
read article
Featured ones: