Тёмный

React useOptimistic hook in Nextjs 14 

Dev Leonardo
Подписаться 5 тыс.
Просмотров 353
50% 1

Опубликовано:

 

2 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 2   
@goncaloshred
@goncaloshred Месяц назад
First of all thanks a lot for the great video! I've been using optimistic hook for a while, but the custom hook that you've created seems to be quite handy! I would like to ask you, how would you manage the optimistic state on a like button? Would you pass the whole array of userIds that have liked to the hook or just some simple boolean "isLiked"? I'm still a new developer and I was passing the whole array of userIds that have liked some content, but doesn't seem to be the best practise as I'd be exposing all the userIds to the client, right?
@DevLeonardo
@DevLeonardo Месяц назад
If you want to display a counter you should do the math (count the userIds) on your server and only return the final number. Everything that is handled in the useOptimistic hook (as every other hook) is already client side. Your client value should just be the number and the optimistic update only do +1 to that number.
Далее
All 17 React Best Practices (IMPORTANT!)
1:46:11
Просмотров 153 тыс.
TanStack Router: Route/Location Masking
10:04
Iran launches wave of missiles at Israel
00:43
Просмотров 820 тыс.
HA-HA-HA-HA 👫 #countryhumans
00:15
Просмотров 565 тыс.
Build a React Component library using Cursor AI
1:35:46
Просмотров 1,3 тыс.
They animated shadcn!
9:14
Просмотров 1,7 тыс.
On-demand revalidation in NextJs 14
16:57
Просмотров 11 тыс.
I Cannot Believe React Made A Hook For This
8:45
Просмотров 104 тыс.
Custom Hooks in React (Design Patterns)
12:56
Просмотров 46 тыс.
The Value of Source Code
17:46
Просмотров 41 тыс.
This New React 19 Hook Will Blow Your Mind
10:51
Просмотров 8 тыс.
Iran launches wave of missiles at Israel
00:43
Просмотров 820 тыс.