TGViewer
Diyorbek.dev | 👨🏻‍💻 Diyorbek.dev | 👨🏻‍💻 @diyorbekk_dev · 381 subscribers
Post #1053 231
useLinkedState has shipped. 🔥

React’da shunaqa holatga duch kelganmisiz?

Tasavvur qiling, sizda Profile Editor bor.
User profilidagi nameni input orqali o‘zgartiryapsiz. Shu paytda local state siz yozayotgan qiymatni saqlab turishi kerak.
Lekin boshqa user profilini ochsangiz, input yangi user’ning nameidan boshlanishi kerak.

Mana shu yerda Octane’da qiziq API chiqardik useLinkedState.


const [name, setName] = useLinkedState(
props.user.id,
() => props.user.name
);



Bu hook’da birinchi argument - source. props.user.id o‘zgarmasa:
→ name siz kiritgan local o‘zgarishlarni saqlab turadi.
user.id o‘zgarsa:
→ hook yangi user’ning nameini darhol qaytaradi.


Va buni qilish uchun:
1 useEffect kerak emas
2 render vaqtida setState qilish kerak emas
3 qo‘shimcha render kutish kerak emas

Yana bir qiziq tomoni bor. useLinkedState yangi source kelganda oldingi source va local value’ni ham olish imkoniyatini beradi claculationda.



const [selection, setSelection] = useLinkedState(
items,
(nextItems, previous) =>
nextItems.find(
(item) => item.id === previous?.value?.id
) ?? nextItems[0] ?? null
);


Masalan, list yangilanganda user tanlagan item hali ham mavjud bo‘lsa - selection’ni saqlab qolish mumkin.
Birinchi render’da previous - undefined.
Source o‘zgarganda esa:



source,
value
}


ko‘rinishida keladi.

Default holatda source va value Object.is orqali solishtiriladi. Kerak bo‘lsa sourceEqual va valueEqual orqali custom comparison ham berish mumkin.

Va useState kabi useLinkedState ham uchinchi tuple qiymati sifatida getValue beradi. Bu async yoki delayed callback ichida eng so‘nggi value’ni o‘qish uchun ishlatiladi.

Qisqasi, useLinkedStatening g‘oyasi juda sodda:
Local state bor, lekin u ma’lum bir source bilan bog‘langan. Source o‘zgarsa, state yangi source asosida qayta boshlanadi.

Sodda API, lekin ayniqsa editable UI’larda juda foydali pattern.

Docs:
https://octanejs.dev/docs/core-apis#use-linked-state
Octane Octane — React's programming model, compiled React's programming model, compiled ahead of time. No VDOM, no rules of hooks.
  • ⚡ 1
More from @diyorbekk_dev
  1. Sep 15, 2026ChatGPT and Codex now support TSRX syntax Highlighting! #tsrx #OctaneJS
  2. Sep 14, 2026Tanner Linsleydan yangilik. Hozirgacha Tanstack Team Octane uchun katta yordam berib kelmo…
  3. Sep 10, 2026Octane Js Hozirda Instagramda bitta content topoldim. Nasib tez kunda òzim yangiliklar qòy…
  4. Sep 9, 2026Ajoyib yangiliklardan biri. Tez orada Open AI butunlay òtadi nasib OctaneJs’ga. Tarqatmay…
  5. Sep 5, 2026Yangi joyni ham tizimlashtirdik. Bir qancha yangi imkoniyatlar qo‘shildi va yangi funksiya…
  6. Sep 5, 2026photo post
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →