linkedin-skill-assessments-quizzes icon indicating copy to clipboard operation
linkedin-skill-assessments-quizzes copied to clipboard

Is the Answer to React Q19 correct?

Open aderchox opened this issue 2 years ago • 2 comments

Q19. When do you use useLayoutEffect? [ ] to optimize for all devices [ ] to complete the update [ ] to change the layout of the screen [x] when you need the browser to paint before the effect runs

Although the fourth option is checked, this is what I've found on web about useLayoutEffect which is completely against the checked option:

Updates scheduled inside useLayoutEffect will be flushed synchronously before the browser has a chance to paint.

From: LogRocket

aderchox avatar Jul 06 '22 07:07 aderchox

Hello @aderchox , thank you for submitting an issue! 👍 We highly appreciate it if you work on it as well.

github-actions[bot] avatar Jul 06 '22 07:07 github-actions[bot]

I believe this question is in fact correct. On reading the docs here it looks like useLayoutEffect stops updates occurring until after the page has loaded so that the effects run after the user can see the page. Otherwise seeing all the effects while elements are loading in would be bad UX.

jefferies917 avatar Aug 02 '22 14:08 jefferies917

Hello @aderchox the answer Looks correct ! As the useLayoutEffect function is triggered synchronously before the DOM mutations are painted. It will run after every render but before the screen is updated. Look at the Example Below this will give you a fair good idea on how it works !

I would Like to refer you to go through this article on useLayoutEffect all of your doubts will be cleared up. 👍

Ref :- (https://react-hooks-cheatsheet.com/uselayoutEffect)

ans

NaNshekhar04 avatar Oct 22 '22 05:10 NaNshekhar04

Yes, I think the answer is correct. Because the rest of the options are factually not possible by the useLayoutEffect

IMPranshu avatar Oct 27 '22 03:10 IMPranshu

You’ll notice that the useLayoutEffect gets executed before the useEffect hook without much concern for DOM mutation.

SRC: https://www.knowledgehut.com/blog/web-development/react-uselayouteffect

@aderchox the question itself can be a bit confusing, but yes, as the other folks commented, the answer is correct.

Hey @Ebazhanov 👋🏻 This issue can be closed. This PR expands that answer.

dagerzuga avatar Nov 12 '22 17:11 dagerzuga