Creating a Custom React Hook: Use Window Size

  Рет қаралды 14,835

DevTuts

DevTuts

Күн бұрын

Пікірлер: 21
@romannikitenko6355
@romannikitenko6355 2 жыл бұрын
beautiful and concise solution. And the main thing is clear even to such a beginner like me! Thank you very much!
@sighamengineering2186
@sighamengineering2186 2 жыл бұрын
if I met this video yesterday, I could have saved a day!
@akugbedestiny8378
@akugbedestiny8378 Жыл бұрын
Thanks.. you are a life saver
@linneagistrand822
@linneagistrand822 3 жыл бұрын
Thank you for a super easy tutorial! Really helped me!
@lykiamusic
@lykiamusic Жыл бұрын
Great tutorial
@fieryninja2374
@fieryninja2374 2 жыл бұрын
quick, easy, and helpful
@trainermono4362
@trainermono4362 2 жыл бұрын
excellent tutorial sir
@shaungaryevans
@shaungaryevans 3 жыл бұрын
Thank you very much for this! worked as a treat in my project :)
@rodrigo41087
@rodrigo41087 4 жыл бұрын
Hello, first of all thanks for the tutorial and a question, when I apply this function in my React project, I notice that the console.logs of other components that have nothing to do with, are fired without any control, that means that all my app is constantly updating without any control, this would affect my performance of my app and how could I avoid this? Sorry for my English
@sasikantnair
@sasikantnair 3 жыл бұрын
If you're consuming the updated width and height in the parent component, then when the parent component re-renders, its child will also re-render. For example, if you've applied the updated value of width and height to the App.js component then the whole app will re-render on any changes to the window height and window width since when the App.js component re-renders, it will make its child components render too. You would have to ensure that the resize handlers are specifically implemented in the component which needs it and not the entire app. If the entire app needs it then you will have to use React.Memo or useMemo hook to avoid unnecessary renders or do prop comparison inside shouldComponentUpdate method in class components. This is the best I could think of. Cheers.
@jamesberesford7310
@jamesberesford7310 3 жыл бұрын
Thank you, this is just what I was looking for!
@pragyan394
@pragyan394 3 жыл бұрын
Thanks, exactly what I was looking for
@hughluo8494
@hughluo8494 2 жыл бұрын
It really does help ! Thanks a lot !!!
@giadalanzalaco6128
@giadalanzalaco6128 3 жыл бұрын
Thank you so much!
@BOSprodz
@BOSprodz Жыл бұрын
Brilliant
@juano141179
@juano141179 3 жыл бұрын
thanks a lot, it is so usefull for me
@vitorvaz6281
@vitorvaz6281 3 жыл бұрын
awnsome man, help me a lot :D thanks!
@nithish9782
@nithish9782 2 жыл бұрын
Can anyone explain Y we need to remove (clean up) the listener? What will happen if we don't remove that.
@devrusso
@devrusso 2 жыл бұрын
What will happen: every time the component re-renders it will start another listener, so there will be 2+ "resize" listeners at the same time. The return/clean up function makes sure that once that the listener is removed before the component re-renders so there will never be more than 1 listener running at the same time. You can easily verify this by removing the clean up, doing a console.log inside the useEffect and updating the state (causing the component to rerender); it will log the same thing twice, thrice or whatever, depending on how many times you've . tl;dr if you don't clean up, everytime the component rerenders it will be the same as be adding another window.addeventlistener line
@harag9
@harag9 Жыл бұрын
I'm so confused with react naming..... why call them "custom hooks" - they are functions, nothing more.
@sunilmaurya6594
@sunilmaurya6594 2 жыл бұрын
this is not working
Кастомные React-Хуки, useToggle, useLocalStorage
22:20
Михаил Непомнящий
Рет қаралды 19 М.
This mother's baby is too unreliable.
00:13
FUNNY XIAOTING 666
Рет қаралды 39 МЛН
Learn React useReducer Hook with Examples
14:19
Lama Dev
Рет қаралды 177 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 481 М.
Build A Custom React JS Modal - Using Hooks (Pop-up Window)
12:27
Code Commerce
Рет қаралды 58 М.
Learn useReducer In 20 Minutes
20:12
Web Dev Simplified
Рет қаралды 510 М.
10 React Antipatterns to Avoid - Code This, Not That!
8:55
Fireship
Рет қаралды 755 М.
3 React Mistakes, 1 App Killer
14:00
Jack Herrington
Рет қаралды 115 М.
EASY React Animation with useGSAP()
12:45
GSAP Learning
Рет қаралды 99 М.
This challenge is a great react custom hook practice problem
12:14
Callbacks, Promises, and Async-Await in JavaScript
11:19
DevTuts
Рет қаралды 7 М.
How to use TypeScript with React... But should you?
6:36
Fireship
Рет қаралды 933 М.
This mother's baby is too unreliable.
00:13
FUNNY XIAOTING 666
Рет қаралды 39 МЛН