Learn React Hooks: useLayoutEffect - Simply Explained!

  Рет қаралды 16,290

Cosden Solutions

Cosden Solutions

7 ай бұрын

Join The Discord! → discord.cosdensolutions.io
Source Code → github.com/cosdensolutions/co...
In this video we will learn about React hooks, starting with useLayoutEffect. This powerful React hook will allow you to run an effect before the browser paints the screen and the component is rendered. This works in exactly the same way as useEffect, with the only difference that useLayoutEffect is synchronous and will block rendering to execute its code. Most of the times useEffect is all you need, but sometimes useLayoutEffect is a better choice!
In this new React world, hooks are here to stay, so it's best to learn them! In this tutorial I demonstrate the useLayoutEffect React hook, and I explain it very simply and in a way that is easy to understand. Enjoy!

Пікірлер: 50
@cosdensolutions
@cosdensolutions 3 ай бұрын
Hey everyone! I just launched 🚀 Project React, which is a course that teaches you React by building a real-world project. It goes way beyond what you see in these videos and walks you through step-by-step on how to build a big and complex application with React! You can check it out here: cosden.solutions/project-react
@erik.schlegel
@erik.schlegel 7 ай бұрын
Just got through your Learn React Hooks playlist. Big fan of your natural and snappy teaching and crisp editing. You were a tremendous help on my react journey and I am very grateful to have found your channel. Links to your content are henceforth being included in all my see more... documentation. Cheers!
@cosdensolutions
@cosdensolutions 7 ай бұрын
Thank you for the kind words! Really glad you found the videos useful ☺️
@mdzaidsiddiqui4262
@mdzaidsiddiqui4262 7 ай бұрын
This is the best useLayoutEffect explanation I've ever seen on yt. Thank you!
@danteDeveloper
@danteDeveloper 7 ай бұрын
Great talk. I just want to point small things setState is not asynchronous, but rendering works asynchronously. Thank you Cosden, what a wonderful speech.
@Leyksnal
@Leyksnal 7 ай бұрын
I really dont need to watch another video , U killed it, thanks
@oProfessorJohnny
@oProfessorJohnny 7 ай бұрын
thank godness, i can not beleave in how you can teach so clearly and direct on the point, you are amazing brow please keep making more videos!
@cosdensolutions
@cosdensolutions 7 ай бұрын
Thank you for the kind words! ☺️ will do
@saalimbhatkar6403
@saalimbhatkar6403 2 ай бұрын
Great Explanation ❤!
@DKevin-rb6vh
@DKevin-rb6vh 2 ай бұрын
Wonderful explanation :) Keep up the great work buddy. Love from India
@kunals6879
@kunals6879 3 ай бұрын
Your videos are more easy to follow than Meta's own React Certification Course
@navinkumarsahu1159
@navinkumarsahu1159 6 ай бұрын
clear to the exact point thanks a lot videsi guy
@brunoguerra7160
@brunoguerra7160 7 ай бұрын
very good!! brings the useTransition hook
@angletheeta
@angletheeta 6 ай бұрын
sir your words are words "welcome back to the last {topic} tutorial video you ever going to after watch" I experienced that so many times in every time watching 2 or 3 tutorials and get nothing from those and come to the cosden solutions yes i do not need to watch another. Thank you for your great effort that you put to uplift the youngsters knowledge . You may deserve over 1M subscribers soon. Hats off from Sri Lanka❤
@Movoid12
@Movoid12 7 ай бұрын
Thank you for the great video 👍
@tigranharutyunyan7674
@tigranharutyunyan7674 6 ай бұрын
You are awesome. Please keep on.
@prakashraj4519
@prakashraj4519 7 ай бұрын
Loved it ❤
@ekchills6948
@ekchills6948 7 ай бұрын
You delivered 👌
@sanjoyrakshit842
@sanjoyrakshit842 7 ай бұрын
Very useful information thanks love from India ❤❤
@ivolovyk
@ivolovyk 7 ай бұрын
Great video, thanks. I think working with DOM is a great case for useLayoutEffect. useLayoutEffect will return the correct sizes of elements via ref on the first render, while useEffect will return 0 because it takes sizes before DOM is ready.
@cosdensolutions
@cosdensolutions 7 ай бұрын
absolutely!
@deepakkashyap6538
@deepakkashyap6538 7 ай бұрын
Great explanation serr 👌, having an indepth idea about hooks in general can help Developers take informed decision while designing the architecture of the application and avoid technical debts interms of performance of the application is considered.
@revanrivani770
@revanrivani770 7 ай бұрын
Amazing video. I had an issue a few days back using react-native. Where I wanted to change the navigation name in a component and if u navigate to “quick” u could see the old name and then change to the new name. So that’s when layouteffect came in clutch
@cosdensolutions
@cosdensolutions 7 ай бұрын
beautiful
@saalimbhatkar6403
@saalimbhatkar6403 2 ай бұрын
Thanks a lot!
@islambn8962
@islambn8962 7 ай бұрын
Thank you for the great tutorial. Although React Docs does not recommend useLayoutEffect, sometimes it's the only way. for ex: persisting DarkMode or checking user login status
@harag9
@harag9 7 ай бұрын
Great video, never seen that use hook before, but interesting how it works compared to useEffect. However I can't think of a reason when you would use it as you say 99% of the time the useEffect is better.
@cosdensolutions
@cosdensolutions 7 ай бұрын
usually used when you need to get sizes and dimensions of html elements through ref to compute things!
@harag9
@harag9 7 ай бұрын
@@cosdensolutionsAhh, good to know. thanks. :)
@rometpastak1
@rometpastak1 7 ай бұрын
Why not bring out some example of thoses cases you actually use it then?
@QuanTran-wt4yt
@QuanTran-wt4yt 5 ай бұрын
normally, i would use it with animations because it requires precise layout
@haikelareff
@haikelareff 5 ай бұрын
how do we set different theme to each multiple (dynamic) pages ex: category pages, or maybe random themes for each blogpost? in next14
@imamdroubi6537
@imamdroubi6537 5 ай бұрын
Thanks a lot for this series, for this specific hook, is it good to use it in a protected route for example ? where you need to check if there is a user in the auth context, it takes some time , and you don't want the user to see the page if he isn't logged in, so does it make sense to use this hook in this situation to block the page from rendering for un-authorized users ?
@cosdensolutions
@cosdensolutions 5 ай бұрын
a better idea would be to show a loader while that happens, with a normal useEffect!
@imamdroubi6537
@imamdroubi6537 5 ай бұрын
@@cosdensolutions Thanks
@serbanmarin-eusebiu
@serbanmarin-eusebiu 7 ай бұрын
I am just curious, because I use quite often use useLayoutEffect for the next scenario, I have a user state in redux, that on every refresh I need to get from the server(golang server), so the base ideea was to use use useLayoutEffect to remove the errors of the application as well to remove the flickering from user useEffect. What’s your ideea about it? Do you think could be done better?
@cosdensolutions
@cosdensolutions 7 ай бұрын
I wouldn't necessarily use useLayoutEffect for that, I would use a normal useEffect and fetch the user and while it is fetching, show a loading spinner on the whole app. Then once the user is available, you can render the rest of the app. No need specifically for useLayoutEffect!
@zeeshanalic
@zeeshanalic 7 ай бұрын
React-router-dom v6 make a video on it. kindly!
@cosdensolutions
@cosdensolutions 7 ай бұрын
yep, it's on the list!
@AykutKlc
@AykutKlc 5 ай бұрын
6:47 how does calling setState stop rendering? is the returned value ignored?
@-mahmoudadel2628
@-mahmoudadel2628 8 күн бұрын
You mean the clean up function, right?
@vesa95
@vesa95 7 ай бұрын
Great, great video, I’m always here to show my appreciation, but Darius, sunt in stare de soc, esti roman? 😱
@cosdensolutions
@cosdensolutions 7 ай бұрын
Da hahahaha
@vesa95
@vesa95 7 ай бұрын
@@cosdensolutions fantastic, ti-am dat add pe linkedIn, nu-mi vine sa cred ca fix persoana de la care abia astept sa posteze ceva nou despre react (din tot yt) e la 50 de km de mine 😂
@bikrantjungbudhathoki3687
@bikrantjungbudhathoki3687 7 ай бұрын
Name of the theme you're using???
@oz4549
@oz4549 7 ай бұрын
2:05 please what do you mean by derive the state? thanks
@Ethereal792
@Ethereal792 7 ай бұрын
Instead of setting `isAdmin` from a useState hook `setIsAdmin`, you can simply add something like `const isAdmin = userId === 1`
@cosdensolutions
@cosdensolutions 7 ай бұрын
Yes exactly
@oz4549
@oz4549 7 ай бұрын
​@@Ethereal792Thanks 🙏
@xxXAsuraXxx
@xxXAsuraXxx 7 ай бұрын
another foot gun from react
Learn React Hooks: useEffect - Simply Explained!
14:07
Cosden Solutions
Рет қаралды 118 М.
The problem with useEffect
11:37
Cosden Solutions
Рет қаралды 31 М.
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 59 МЛН
MEGA BOXES ARE BACK!!!
08:53
Brawl Stars
Рет қаралды 34 МЛН
Каха ограбил банк
01:00
К-Media
Рет қаралды 10 МЛН
Пробую самое сладкое вещество во Вселенной
00:41
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 457 М.
Reviewing your React Code: Episode #3
14:27
Youssef Benlemlih
Рет қаралды 6 М.
Refactoring a React component - Design Patterns
15:19
Cosden Solutions
Рет қаралды 91 М.
Learn React Hooks: useTransition - Simply Explained!
10:41
Cosden Solutions
Рет қаралды 21 М.
Stop Doing this as a React Developer
12:27
CoderOne
Рет қаралды 160 М.
You Are Using useEffect Wrong
14:40
Cosden Solutions
Рет қаралды 32 М.
Learn React Hooks: useReducer - Simply Explained!
13:48
Cosden Solutions
Рет қаралды 46 М.
Learn React Hooks: useDeferredValue - Simply Explained!
12:02
Cosden Solutions
Рет қаралды 12 М.
Never Forget React forwardRef Again
9:33
Coding in Public
Рет қаралды 14 М.
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 59 МЛН