Let's talk about `useDeferredValue` hook from #reactjs 18.

In some cases it could replace `debounce` func.

It lets you defer updating a part of the UI.

Small 🧡
During the initial render, the returned deferred value will be the same as the value you provided.

During updates, React will first attempt a re-render with the old value (so it will return the old value), and then try another re-render in background with the new value.
The values you pass to it should either be primitive values (strings, numbers) or objects created outside of rendering.

If you create a new object during rendering and immediately pass it to useDeferredValue, it will be different on every render, causing unnecessary re-renders.
useDeferredValue is integrated with <Suspense>. If the background update caused by a new value suspends the UI, the user will not see the fallback.

They will see the old deferred value until the data loads.
There is no fixed delay caused by useDeferredValue itself.

As soon as React finishes the original re-render, React will immediately start working on the background re-render with the new deferred value.
The background re-render caused by useDeferredValue does not fire Effects until it’s committed to the screen.

If the background re-render suspends, its Effects will run after the data loads and the UI updates.
Stupid GPT is lying to me again, saying useDeferredValue returns a tuple 😑😑

It is not!

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Vladimir Kosenko 🀘

Vladimir Kosenko 🀘 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @web3brightside

Mar 23
Hey folks!

Let's talk about server-sent events (SSE) in JavaScript!

SSE is a server technology that allows a web page to get updates from a server in real-time.

It's a great alternative to web sockets for some use cases.

Let's dive in! 🧡
To start using SSE in your JavaScript code, you first need to create a new EventSource object and specify the URL of the server endpoint that will be sending the events.

Here's an example:

const eventSource = new EventSource('/events');
Once you have the EventSource object, you can listen for events using the addEventListener method: Image
Read 9 tweets
Mar 19
ChatGPT will get you nowhere and you will also embarrass yourself.

Yes, it's a hook. Now let's talk a little bit about why ChatGPT is total bullshit (ATM) and I won't be giving up on Google.

I'll talk in the context of web development and the knowledge around that area.

πŸ§΅πŸ‘‡ Image
What's the main problem with ChatGPT?

The fact that you're left with it on your own.

πŸ‘‡
How do you usually realise that an article you come across is complete rubbish, written by an amateur?

More often than not, an article has some sort of social rating - feedback, comments from angry users who argue that the author's solution is nonsense.

πŸ‘‡
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(