Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Windows Tipps & SecurityNighthawk M7 Pro im Test: Flexibler, aber teurer 5G-Router(21.09.2026 um 10:30 Uhr)
Sichere ProgrammierungNeue Gmail-Funktion: So sparst du jetzt Zeit bei Einmalcodes(21.09.2026 um 10:00 Uhr)
Sichere ProgrammierungYour GIF exporter is fine — the container is the problem(21.09.2026 um 10:01 Uhr)
Sichere ProgrammierungCSS, Motion, or GSAP? I Choose by Who Owns the Animation(21.09.2026 um 10:12 Uhr)
Windows Tipps & SecurityNighthawk M7 Pro im Test: Flexibler, aber teurer 5G-Router(21.09.2026 um 10:30 Uhr)
Sichere ProgrammierungNeue Gmail-Funktion: So sparst du jetzt Zeit bei Einmalcodes(21.09.2026 um 10:00 Uhr)
Sichere ProgrammierungYour GIF exporter is fine — the container is the problem(21.09.2026 um 10:01 Uhr)
Sichere ProgrammierungCSS, Motion, or GSAP? I Choose by Who Owns the Animation(21.09.2026 um 10:12 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Object.assign() usage in Zustand's source code.

In this article, we will understand how Object.assign() is used in Zustand’s source code. The above code snippet is from vanilla.ts, when you set a state, Object.assign is used to update your state object. Let’s first understand the ba…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




In this article, we will understand how Object.assign() is used in Zustand’s source code.



Image description



The above code snippet is from vanilla.ts, when you set a state, Object.assign is used to update your state object.



Let’s first understand the basics of Object.assign:






Object.assign()



The Object.assign() static method copies all enumerable own properties from one or more source objects to a target object. It returns the modified target object.




const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };

const returnedTarget = Object.assign(target, source);

console.log(target);
// Expected output: Object { a: 1, b: 4, c: 5 }

console.log(returnedTarget === target);
// Expected output: true






b value in the target object is replaced with b value in source object.



Really simple right? let’s now run some experiments and understand how Zustand’s setState leverages Object.assign() method.






Object.assign() in Zustand’s source code:






// pulled from: https://github.com/pmndrs/zustand/blob/main/src/vanilla.ts#L76
state = (replace != null ?
replace :
typeof nextState !== "object" ||
nextState === null) ?
nextState :
Object.assign({}, state, nextState);






That’s nested ternary operator there in the above code snippet. if the replace is not null, state will be replace or if the nextState is not an object, just return nextState as is but what we are interested in is Object.assign({}, state, newState).



Let’s first log and see what is in state and nextState when you update your state. The example I picked is from demo example in Zustand’s source code. I modified the code a bit so we can put some console statements and run these experiments.



Image description



Image description



In this simple example, when the count is incremented, it comes down to updating the state object using Object.assign.



Next time, you are trying to perform some updates on your JSON object, use the Object.assign.






About us:



At Think Throo, we are on a mission to teach the best practices inspired by open-source projects.



10x your coding skills by practising advanced architectural concepts in Next.js/React, learn the best practices and build production-grade projects.



We are open source — https://github.com/thinkthroo/thinkthroo (Do give us a star!)



Looking to build bespoke web systems for your business? Contact us at [email protected]






About the author:



Hey, I’m Ram. I am a passionate software engineer/OSS Tinkerer.



Checkout my website: https://www.ramunarasinga.com/






References:




  1. https://github.com/pmndrs/zustand/blob/main/src/vanilla.ts#L76


  2. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Object.assign() usage in Zustand's source code.

Thematisch verwandte Begriffe: Objectassign, usage, Zustands, source code · 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 ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94036 | A security flaw has been discovered in D-Link DIR-X1860 and DIR-X1860Z u…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick