React Tips and Tricks that Will Make You A Better React Developer

  Рет қаралды 86,114

PedroTech

PedroTech

Күн бұрын

In this video I will go over 3 tips and tricks that will improve your react skills by a lot. At the end I also go on a tangent about whether you should use the context api or not.
Join our Discord: / discord
🚀 Learn ReactJS By Building 6 Projects: codedamn.com/learn/reactjs-pr...
🐙 GraphQL Course: codedamn.com/learn/graphql-fo...
► Buy Crypto on Coinbase: coinbase-consumer.sjv.io/PedroTech
Social
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Website: machadopedro.com
Linkedin: / machadop1407
Instagram: / _pedro.machado_
Github: github.com/machadop1407
Business Email: pedro@pedrotech.co
Timestamps
00:00 | Intro
00:39 | Optional Chaining
10:18 | Composition
16:45 | Context API vs Prop Drilling
Tags:
- ReactJS Tutorial
- ReactJS and MySQL
- NodeJS Tutorial
- API Tutorial
#reactjs #tips

Пікірлер: 153
@Ayomikun
@Ayomikun Жыл бұрын
Just a small note for that last tip. You can have multiple contexts and providers in your app, so an alternative solution could be to just add an additional context. In your example, maybe 1 for the word and word setter, and another for the count and count setter. You could even go further and have 4 contexts: 1 for each value and value setter. Then you could call useContext for only the context values needed for each component.
@dearesthui
@dearesthui Жыл бұрын
You could also use React useMemo hook to prevent re-rendering of unrelated states.
@IncomingLegend
@IncomingLegend Жыл бұрын
but can you have multiple contexts wrapped around each other?
@farhankadir196
@farhankadir196 2 жыл бұрын
Amazing! Thanks for the video, Pedro! I literally used optional chaining yesterday and was the same scenario of a useEffect() but fetching data from the db! It worked like a charm!
@Rajatkumar-iy4px
@Rajatkumar-iy4px 2 жыл бұрын
Great content. I learned about use cases for Optional chaining and how you showed use cases for Context API vs Prop Drilling. I would definitely love some advanced react patterns which can be helpful in large scale applications.
@alpaca_growing_kit
@alpaca_growing_kit 2 жыл бұрын
As always, solid React content. I keep learning whenever you throw out new videos so keep them coming.
@jitx2797
@jitx2797 2 жыл бұрын
Pedro you are just awesome man. Followed your MySQL react tutorial and it was just awesome.
@donmikkodanm.olmillo8154
@donmikkodanm.olmillo8154 2 жыл бұрын
I love your guides. thank you so much! will surely love to suggest to make this one a playlist on your channel so that it will be easily navigate. and also a series of tips and tricks good for any level especially beginners not just react but also JS. thank you!
@milburngomes2406
@milburngomes2406 Жыл бұрын
Really great video!! Very useful in practical situation. Well explained and to the point. Keep up the good work!!
@KILLCHRISU
@KILLCHRISU Жыл бұрын
incredible tips! gonna use these on my next project. subbed 👍
@revasseurborn2000
@revasseurborn2000 2 жыл бұрын
Subscribed right away! U r clear with what you to want deliver ..!
@akselipalmer5729
@akselipalmer5729 Жыл бұрын
Thank you for the Video! Super helpful.
@Marcus-09
@Marcus-09 2 жыл бұрын
amazing video and high quality content, thansk Pedro. Cheers from Italy
@rohanraisaxena1514
@rohanraisaxena1514 2 жыл бұрын
Please make more examples...when to use context api and when to use prop drilling... Btw this video helps me alot..thanks for this🤗
@ghostcatcher1279
@ghostcatcher1279 2 жыл бұрын
For me I like to avoid prop drilling as much as possible as for me it's harder to debug and I often forget what props go where. For smaller applications I prefer contextAPI because it's fast to code out and easy to use. For larger applications I prefer to use Redux for state management on an app such as an Airbnb clone or maybe an Amazon clone.
@varanasi47
@varanasi47 2 жыл бұрын
@@ghostcatcher1279 yep i think contextAPI is meant for small scale apps or features only , for something like amazon clone , always use something like redux
@windowspowerpoint1825
@windowspowerpoint1825 2 жыл бұрын
@@varanasi47 There's a lot of options, Zustand is great, so is Redux toolkit, there is no one to rule them all. They all have pros and cons.
@danshilm
@danshilm 2 жыл бұрын
I'd personally only use prop drilling for 2 (very rarely 3) layers of components, and that too only for those that make naturally make sense. If you find yourself having to prop drill through more than 3 layers, consider taking a step back and thinking about the architecture of your app. There might be simpler/more intuitive ways to achieve the same thing.
@pranitmogal715
@pranitmogal715 Жыл бұрын
There is no proper guide on whether you should go with prop drilling or context API, Just validate your code in terms of necessity, whether it is required to do or not and then proceed, Context API is always a good choice when the data is stored does not have frequent updates..
@Pablo-gl5jz
@Pablo-gl5jz 2 жыл бұрын
Absolutely outstanding. Thanks a lot Pedro.
@alexcoroza4518
@alexcoroza4518 9 ай бұрын
I watched your react course/playlist and now i am trying to copy the spotify app with react. I remember you said and recommend to use context api. Me as a react beginner, i put my states in a GlobalContext. Now i changed the volume level via a slider and my spotify app goes like crazy, it was rerendering the whole app on every volume level change lol. Since then i started to learn more about this context api and states then found this video discussing the cons of context api
@ezequielvallejo9352
@ezequielvallejo9352 Жыл бұрын
Nice!! Loved the first 2.
@JeanDidier
@JeanDidier Жыл бұрын
TYVM for the 2nd tip with composition
@marcuslorenzo9705
@marcuslorenzo9705 2 жыл бұрын
Brother your explanation of Composition helped me understand props. It clicks now...I get it. Muito obrigado irmao (assuming you speak Portuguese 😂). You're awesome.
@primozbabsek6744
@primozbabsek6744 2 жыл бұрын
That is actually very useful. Can't believe I didn't use those so far...
@NamNguyen-oz8uj
@NamNguyen-oz8uj 2 жыл бұрын
Thank Pedro,look forward to your video about contextAPI, redux, redux tollkit
@chikwandaacademy
@chikwandaacademy 2 жыл бұрын
Thank you so much Pedro. Your react full stack web development course help me big time when I just started my software development career. Am so blessed by your content. Thank you.
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
Glad I could help!
@thespikything
@thespikything Жыл бұрын
Worth mentioning that you can you get around the unnecessary re-rendering (when using too 'large' a Context) by memo-izing components.
@user-xh1ky3mf3y
@user-xh1ky3mf3y 5 ай бұрын
Absolutely outstanding !
@Mimi-rv5rb
@Mimi-rv5rb 2 жыл бұрын
Very useful, thanks Pedro
@universecode1101
@universecode1101 2 жыл бұрын
Good job Pedro ✌🏻 useful tips
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
Thanks! 😃
@sealuke2724
@sealuke2724 2 жыл бұрын
Nice tutorial! Hope you will make useReducer, Jotai, react-query for state management like a pro!
@korbinschulz2093
@korbinschulz2093 Жыл бұрын
Just finished my first decent react project and used if statements to conditionally render, wish i had learned about optional chaining sooner!
@akhilkumarsingh5041
@akhilkumarsingh5041 Жыл бұрын
Congrats for 70k+ subs i am following u since 8k subs.
@PedroTechnologies
@PedroTechnologies Жыл бұрын
Thank you so much 😀 Its been a long journey, good to know u were here from the beginning!
@az1nn
@az1nn 2 жыл бұрын
Very cool!! Nice tips for beginners
@semx8372
@semx8372 2 жыл бұрын
Soooo useful video!! Thx alot !
@pavelisel4127
@pavelisel4127 2 жыл бұрын
Good Content Pedro. Keep it up 👍
@Slimgoodie0216
@Slimgoodie0216 Жыл бұрын
Great video!
@inspirationalquotes5840
@inspirationalquotes5840 2 жыл бұрын
Thank you Pedro
@TheGluemess
@TheGluemess Жыл бұрын
fantastic content, keep it up!
@ScriptyVijay
@ScriptyVijay 2 жыл бұрын
Subscribed 👍 well explained
@iprogrammer_v3809
@iprogrammer_v3809 2 жыл бұрын
Good one thanks 😇
@roman_k89
@roman_k89 2 жыл бұрын
very cool - i didn`t know anything of that, thanks!
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
Glad to help!
@psydook
@psydook 2 жыл бұрын
Very helpful, thanks
@Tinwall72
@Tinwall72 2 жыл бұрын
Hey Pedro thanks for the nice videos, i really love them.
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
Glad to hear that!
@freemenclub
@freemenclub Жыл бұрын
Useful!
@abdessamade6995
@abdessamade6995 Жыл бұрын
great content♥
@willyhorizont8672
@willyhorizont8672 Жыл бұрын
@ 13:25 yo pedro what's your best way create card component but one has ref on it ? do you create 2 similar component one without forwardRef and the other with forwardRef?
@toastrecon
@toastrecon 2 жыл бұрын
I'm still new to TypeScript, but I wonder how optional chaining works with TS or if TS kind of makes some of that unnecessary? I mean, you'd have to define all of that beforehand or you'd get compile errors? Thanks, Pedro! These videos are amazing.
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
It works perfectly with TS since it won't allow you to access optional keys in objects unless you put the question mark. So in both you have to use optional chaining, but in TS it will give you an error message if you don't :)
@SteveBoyer10
@SteveBoyer10 2 жыл бұрын
Works the same as he shows in the video. Keep learning TS. It’s worth it!
@charbouy
@charbouy Жыл бұрын
Thank you bro, lets go for those 100k subscribers!
@PedroTechnologies
@PedroTechnologies Жыл бұрын
@arturmavlidov247
@arturmavlidov247 2 жыл бұрын
Thanks!!
@ShubhamSingh-it4om
@ShubhamSingh-it4om 2 жыл бұрын
Hey Pedro, Thanks for your awesome videos. Will you please make a tutorial on creating multi-vendor marketplace using Next Js + Mongodb or by MERN stack. It will an awesome learning.
@usmanmughal_mirza2094
@usmanmughal_mirza2094 Жыл бұрын
Wow .. Composition is awesome .. optional chaining i already know ..
@shivanshpatel4072
@shivanshpatel4072 Жыл бұрын
i like the composition part bro
@harrisonekpobimi4764
@harrisonekpobimi4764 2 жыл бұрын
Nice stuff buddy,, with this issue with context, what would you suggest
@w1ckh3ad84
@w1ckh3ad84 2 жыл бұрын
Hey, nice Video, I have got a fix for the context rerender issue. You create two contexts, one for the value and one for the setter.
@mohamadbadrian9655
@mohamadbadrian9655 Жыл бұрын
very useful tnx
@afickredox4121
@afickredox4121 2 жыл бұрын
rare content , thanks bro
@AM-nm6ts
@AM-nm6ts 2 жыл бұрын
thanks!
@mooder3247
@mooder3247 2 жыл бұрын
I'm using context api for a really big project what i came up with is sperating the contexts to small pieces that responsible for smal pieces of the UI and trying to avoid global states and use local states and most importantly use SWR for server states and so far everything is working good
@ethanj1533
@ethanj1533 2 жыл бұрын
What’s SWR
@user-wl2xp8yo6x
@user-wl2xp8yo6x 2 жыл бұрын
Тоже хочу добавить: 1. Отделяйте бизнес логику приложения отдельно от реакта. 2. Используйте хуки типа react-query, swr и не использовать стейт менеджеры типа redux, effector (Только для глобальных данных)
@diegounanue
@diegounanue Жыл бұрын
This is a pattern I’m looking forward of how to implement. Using a custom hook with react query for state management.
@sonamohialdin3376
@sonamohialdin3376 2 жыл бұрын
So good tutorial
@sonlethanh5653
@sonlethanh5653 Жыл бұрын
About the Context API. One way to prevent rerender is by using the children props for the child component in the AppContext Provider. The child component won't rerender if the state of context doesn't change
@ponderatulify
@ponderatulify Жыл бұрын
What if you use useCallback to memoize the setters passed down from the provider components.
@Bertoos8
@Bertoos8 2 жыл бұрын
This channel is like a 🚀
@rogi9696
@rogi9696 2 жыл бұрын
Actually i'm using jotai and react query together and pretty much solves all of the problems and they are very intuitive too
@nelsonmichael4519
@nelsonmichael4519 Жыл бұрын
I might be wrong, but don't you still need to check if the data is actually available even if you're using something like react query? I understand we would no longer need useEffect() when we're using those libraries.
@rogi9696
@rogi9696 Жыл бұрын
@@nelsonmichael4519 The react query itself returns a lot of useful information about the data, isLoading, isFetching and others useful resources when building an app
@DuyTran-ss4lu
@DuyTran-ss4lu Жыл бұрын
awesome
@nogombrate
@nogombrate Жыл бұрын
Hello i have 2 react questins that i whoud like to ask 1. If we use 2 or 3 different Context for diffrent part of app but we warp all providers on index.js will they reneder all components that use different part of state from each context (example state change in context 1 will that rerender components that use state from context 2 since they have same entry point or we need to wrap only components that need state in provider) 2. I was told that using React.memo() in component and useMemo() to wrap reference value props coming in that components is somehow bad and i whoud like to now if that is true
@canto_bjj
@canto_bjj 2 жыл бұрын
bom demais man
@Holfter
@Holfter 2 жыл бұрын
Não vi ainda mas ja sei que vai ser bom kkkkk
@viniciusm.m.7822
@viniciusm.m.7822 2 жыл бұрын
Parabéns pela contribuição brother! Eu por enquanto não posso, mas sei q isso incentiva bastante!
@Holfter
@Holfter 2 жыл бұрын
@@viniciusm.m.7822 Quando puder tenho certeza que você vai contribuir.
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
Muito obrigado mano! Agradeço pelo apoio :)
@pavelisel4127
@pavelisel4127 2 жыл бұрын
I liked the video but I do not agree with the argument that the state should be initialized in null. Could you point me to an article describing why is a better practice to start with null than with an empty array. Thanks
@mmareplays4610
@mmareplays4610 Жыл бұрын
"I don't know what I did to deserve 70k subs, but we're aiming for 100k by the end of the year haha" gatto love this guy hahaha
@PedroTechnologies
@PedroTechnologies Жыл бұрын
❤️❤️❤️
@lkkope
@lkkope 2 жыл бұрын
man, this video would have saved me a lot of headache yesterday.
@fandross_
@fandross_ 2 жыл бұрын
muito bom!
@ogunmokunademola7292
@ogunmokunademola7292 Жыл бұрын
If I set my initial state to null, if the dB is empty it will definitely return an empty array. And an empty array is truthy, so how do we go about that
@appuser
@appuser Жыл бұрын
Your composition over inheritance example was great and really got me thinking. However, forcing all components to look for the props.children property you break YAGNI/ISP (forcing all cards to implement {props.children), and are in-fact relying on a form of inheritance (inheriting the check for props.children). A more compositional alternative would be to have a component that is composed from a and element, perhaps called or something... So you don't have to repeat yourself (DRY), but you also don't have to implement features that aren't going to be used. In saying all that, your example is still somewhat compositional, and probably simpler as you require less actual components to implement it, and simpler always wins (KISS).
@robertbontas3228
@robertbontas3228 2 жыл бұрын
Hello pedro, i found you when you made the livestream of 4 hours making the Social Media application. I wanna thank you for everything. I would really appreciate if u can make something like a user profile that stocks the profile picture as a url of firebase reference, in a mysql column. I need that because i wanna make an app that work on my-sql but i wanna store images on firebase. That would be awesome, thanks brother.
@mav3ricktv
@mav3ricktv Жыл бұрын
I remember working with a lot of coffeescript which, although old, uses optional chaining. I kept asking myself why doesn't typescript implement such a feature and boom.. one day colleague introduced it to us and yeah, I don't think there has been a day I haven't used it
@JamesSmith-yj7wq
@JamesSmith-yj7wq 2 жыл бұрын
Hey Pedro can you make some videos on Class Components with a dummy project..
@einfacherkerl3279
@einfacherkerl3279 5 ай бұрын
Simple solution is to have smaller context that only contain specific data. For instance auth context should only have auth data and nothing else. In that way you can avoid this problem. Also those who are suggesting to React.memo(), it wont work because it only operates on props not internal states of the component.
@learn029
@learn029 2 жыл бұрын
I can't able to install create react app with yarn which step of command i have to follow
@MrPaulPhan
@MrPaulPhan 2 жыл бұрын
To help reduce the re-renders, could we memo here?
@richardwilliam7030
@richardwilliam7030 2 жыл бұрын
Great Pedro I need help I want to build an app with multiple layout Login can have different layouts and dashboard can have different layouts And also I need help in securing a react app
@hassamulhaq7762
@hassamulhaq7762 Жыл бұрын
09:35 👍 Helpful tips.
@JackHartwig
@JackHartwig 2 жыл бұрын
Baller
@yousafsabir7
@yousafsabir7 Жыл бұрын
Isn't Redux good solution to both context & prop drilling?
@chesterxp508
@chesterxp508 2 жыл бұрын
GoodJob!
@windowspowerpoint1825
@windowspowerpoint1825 2 жыл бұрын
The whole []/null, like, just use something like trpc, graphql or react-query like, they all provide methods to handle error catching
@filipevalentegomes2383
@filipevalentegomes2383 2 жыл бұрын
With recoil, zustang, redux with redux toolkit and so many others, isn't it just better to use one of these and get good at it, instead of using the context api?
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
Thing is, a great library is not just made out of how performant it is, we should also account for dev experience. Context api is amazing in the sense that it is simple and easy to use. I will make a more in depth vid on this :)
@filipevalentegomes2383
@filipevalentegomes2383 2 жыл бұрын
@@PedroTechnologies awesome, thanks for the video and taking time to reply
@igorigmatenko504
@igorigmatenko504 2 жыл бұрын
What about AWS Amplify(alternative for Firebase)?
@johnpaulpineda2476
@johnpaulpineda2476 2 жыл бұрын
Finally
@dotdot-zp5vx
@dotdot-zp5vx Жыл бұрын
you talk like morty from rick and morty , love your playlists though ive been watching your videos for the last 4 months learning react
@SporteeGamer
@SporteeGamer Жыл бұрын
Hello is it necessary to learn css for learning react
@PedroTechnologies
@PedroTechnologies Жыл бұрын
No! But at least understand the basics of css cause thats useful for everything (not only react)
@yakob-g
@yakob-g Жыл бұрын
the react docs are nice tho
@tonyto2009
@tonyto2009 2 жыл бұрын
Optional chaining is not the solution for working with data. The problem is it hides the issue of missing properties and in some cases it might force the app to execute a wrong condition that should have triggered an error if `?` was omitted
@cryptodev2615
@cryptodev2615 2 жыл бұрын
Recoil is the best state manager imo It's so easy.
@raushanraj_99
@raushanraj_99 2 жыл бұрын
♥️
@user-og7de8ih4f
@user-og7de8ih4f 2 жыл бұрын
Do anyone know intro music link ?
@huzafaarshad973
@huzafaarshad973 2 жыл бұрын
but also when parents props changes all its child render again so situation is still same tree render again what makes difference ?can anyone explain or correct me if I am wrong
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
The thing is, it will only re-render if the state passed through the props changes. If u are using the context api and any of the states inside the context change the value, all the components grabing anything from the context will re-render
@huzafaarshad973
@huzafaarshad973 2 жыл бұрын
@@PedroTechnologies ahh 👍 thanks now it is clear ☺️
@Leyksnal
@Leyksnal Жыл бұрын
Please make a video on change stream
@taulantisaku4688
@taulantisaku4688 Жыл бұрын
A 99 years old still drinking beer, savage!
@Randomguy48279xyz
@Randomguy48279xyz 2 жыл бұрын
👍
@AM-nm6ts
@AM-nm6ts 2 жыл бұрын
22.00 and if we use redux with context?
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
Both are good options, but with their own benefits and negatives. I will explain more on my context api vs prop drilling vid
@AM-nm6ts
@AM-nm6ts 2 жыл бұрын
@@PedroTechnologies thanks a lot ,
@husseinelkhatib754
@husseinelkhatib754 2 жыл бұрын
@@PedroTechnologies Waiting u. Thanks a lot.
@windowspowerpoint1825
@windowspowerpoint1825 2 жыл бұрын
why
@dailymeow3283
@dailymeow3283 2 жыл бұрын
The correct title should be "Become a Bro in React"
@Spytie1
@Spytie1 2 жыл бұрын
what about creating a context for each of the frequently changing states ? so it only rerenders components that use the state
@c3ltic1
@c3ltic1 2 жыл бұрын
But you can have as many context apis separate as you want no?
@htmoh8115
@htmoh8115 Жыл бұрын
I was following a tutorial. At the react page I got stuck.
4 Ways To Fetch Data in React
31:17
PedroTech
Рет қаралды 54 М.
All useEffect Mistakes Every Junior React Developer Makes
22:23
[柴犬ASMR]曼玉Manyu&小白Bai 毛发护理Spa asmr
01:00
是曼玉不是鳗鱼
Рет қаралды 48 МЛН
Black Magic 🪄 by Petkit Pura Max #cat #cats
00:38
Sonyakisa8 TT
Рет қаралды 17 МЛН
WHY IS A CAR MORE EXPENSIVE THAN A GIRL?
00:37
Levsob
Рет қаралды 6 МЛН
All The JavaScript You Need To Know For React
28:00
PedroTech
Рет қаралды 545 М.
I Reviewed Your Beginner React Code
12:36
Josh tried coding
Рет қаралды 97 М.
3 Beginner React Mistakes That Can Ruin Your App
20:19
Web Dev Simplified
Рет қаралды 101 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 449 М.
ALL React Hooks Explained in 12 Minutes
12:21
Code Bootcamp
Рет қаралды 55 М.
6 State Mistakes Every Junior React Developer Makes
15:53
Lama Dev
Рет қаралды 262 М.
React Query Is (Still) Essential - My Favorite React Library
11:04
Theo - t3․gg
Рет қаралды 139 М.
Samsung or iPhone
0:19
rishton vines😇
Рет қаралды 8 МЛН
Carregando telefone com carregador cortado
1:01
Andcarli
Рет қаралды 1,9 МЛН
Which Phone Unlock Code Will You Choose? 🤔️
0:14
Game9bit
Рет қаралды 12 МЛН
#miniphone
0:18
Miniphone
Рет қаралды 11 МЛН