Zum Hauptinhalt springen
•
YouTube Security Videosheise & c't: Sheldons nerdiges Kostüm erklärt(27.10.2026 um 15:00 Uhr)
••
Windows Tipps & SecurityForget cloud gaming, DroidDeck brings PC Game Pass to Android natively(27.10.2026 um 15:17 Uhr)
•
Windows Tipps & SecuritySaug-Wisch-Roboter für 665 Euro: Ecovacs X12 52 Prozent günstiger(27.10.2026 um 14:07 Uhr)
•
Windows Tipps & SecuritySamsung hat meinen Smartphone-Trade-in in einen Albtraum verwandelt(27.10.2026 um 14:23 Uhr)
•••
Windows Tipps & Security64-GB-USB-Stick mit zwei Anschlüssen: Amazon-Bestseller für 15,29 Euro(27.10.2026 um 15:39 Uhr)
•
Windows Tipps & SecurityWindows 11 26H2 seit 21. Oktober 2026 allgemein verfügbar - BornCity(27.10.2026 um 08:21 Uhr)
••
YouTube Security Videosheise & c't: Sheldons nerdiges Kostüm erklärt(27.10.2026 um 15:00 Uhr)
••
Windows Tipps & SecurityForget cloud gaming, DroidDeck brings PC Game Pass to Android natively(27.10.2026 um 15:17 Uhr)
•
Windows Tipps & SecuritySaug-Wisch-Roboter für 665 Euro: Ecovacs X12 52 Prozent günstiger(27.10.2026 um 14:07 Uhr)
•
Windows Tipps & SecuritySamsung hat meinen Smartphone-Trade-in in einen Albtraum verwandelt(27.10.2026 um 14:23 Uhr)
•••
Windows Tipps & Security64-GB-USB-Stick mit zwei Anschlüssen: Amazon-Bestseller für 15,29 Euro(27.10.2026 um 15:39 Uhr)
•
Windows Tipps & SecurityWindows 11 26H2 seit 21. Oktober 2026 allgemein verfügbar - BornCity(27.10.2026 um 08:21 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

useRef Hook in react

useRef : The useRef Hook allows you to persist values between renders. It can be used to store a mutable value that does not cause a re-render when updated. It…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!




useRef :



The useRef Hook allows you to persist values between renders.



It can be used to store a mutable value that does not cause a re-render when updated.



It can be used to access a DOM element directly.






Syntax :






import { useRef } from 'react';

const myRef = useRef(initialValue);










Important Points :



When you call useRef, it returns a plain JavaScript object with a single property called current.



The most important useRef is that changing its value does not trigger a component re-render.






Example Code :






import React from 'react'

import { useState, useRef } from "react";

function UserRef() {

let normalVar = 5;

const myRef = useRef(5);

const [count, setCount] = useState(5);

return (
<div>
<p>Normal Variable: {normalVar}</p>
<p>Ref Variable: {myRef.current}</p>
<p>State Variable: {count}</p>

{/* Increments value in memory, but UI does not change */}
<button onClick={() => normalVar++}>
Increment Normal
</button>

{/* Increments ref.current, but UI does not change */}
<button onClick={() => myRef.current = myRef.current + 1}>
Increment Ref
</button>

{/* Increments state and forces the component to re-render, displaying new values */}
<button onClick={() => setCount(count + 1)}>
Increment State
</button>
</div>
);
}
export default UserRef;










Explanation :



First you click a normal variable button the value change only memory but, dosen't change the UI.



Then click the useRef variable button two time it's also dosen't change UI.



Then click the state variable button it changes and updates the values both useRef and state variables.



Because ,the useRef remembers the values and shows the values when the component re-renders.



The useRef button clicked by two times so, it's updates 7 and state variable clicked by one time it shows the value 6.






Output :





Intelligence Digest — kostenlos Täglich die wichtigsten Security-News · jederzeit abbestellbar
Community Rating & Social Proof
⭐ Leser-Wertung
–
Ø / 5.0
Noch keine Leser-Bewertungen
War diese Seite hilfreich?
0
Jetzt Bewertung abgeben
🟢 Niedrig (1-3.9) 🟡 Mittel (4.0-6.9) 🔴 Hoch (7.0-8.9) Kritisch (9.0-10.0)

Verwandte Story-Cluster & Quellen (Vektor-KI)

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten useRef Hook in react

Thematisch verwandte Begriffe: useRef, Hook, react · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Nächster Beitrag