DEV Community


Discussion on: React: Using the State Hook

iyashsoni profile image
Yash Soni

Hey @link2twenty , a follow-up question, if we do go ahead with the first approach that you just showed, won't it have a performance impact? Consider the following:

const [quote, setQuote] = React.useState("");
const [author, setAuthor] = React.useState("");

Now if we get a fresh quote in useEffect(...) and I update both quote and author on success, won't it cause 2 re-renders due to 2 set states?

Thread Thread
link2twenty profile image
Andrew Bone Author

Funnily enough, I was actually looking into this last night. I'd read a few places that several sets together sort of roll into one to save rendering lots. So I've made this quick proof of concept.

The number will go up each time we run render (based on either of those states changing).