4 React Best Practices That Will Make You A PRO

Поделиться
HTML-код
  • Опубликовано: 6 сен 2024

Комментарии • 159

  • @Pointcut
    @Pointcut 2 года назад +44

    Personal Timestamps
    03:21 - Separating your functionality into components will prevent unnecessary re-renders.
    07:43 - Use empty (or ..) fragment tags to add multiple
    elements to a React Component without wrapping it in an extra DOM node (such as a )
    10:39 - Sometimes it's best to separate your useState hook data into multiple hooks, instead of using a single hook with an object.
    14:50 - Typechecking your props is important

    • @hoaxygen
      @hoaxygen Год назад +2

      Thanks for saving me 20 unnecessary min!

    • @TagFul19
      @TagFul19 Год назад

      @@hoaxygen lol

    • @succeedwithuttam2271
      @succeedwithuttam2271 Год назад

      Typechecking by using proptypes. simply amazing.

  • @superurgmail
    @superurgmail 2 года назад +72

    How about a video on debugging in React?
    There doesn't seem to be many good videos on debugging React. It could be super useful. :)

    • @PedroTechnologies
      @PedroTechnologies  2 года назад +20

      Great suggestion!

    • @badcode8029
      @badcode8029 2 года назад +2

      yes thats all i want to see a various way to debugging react from every developer

  • @fhkodama
    @fhkodama 2 года назад +5

    Pedro, excelente vídeo! Se você tiver outras "best practices", pode fazer mais desse tipo de vídeo que ajuda bem nós que estamos começando! Estou mudando de carreira e seus vídeos estão me ajudando bastante. Fiquei feliz de saber que vc é um brasileiro morando em Vancouver. Eu acabei de chegar em Ottawa. Abração e parabéns!

  • @PPMBlast
    @PPMBlast 2 года назад +2

    React Dom and life cycle are super important and I feel go unmentioned in most tutorials. Really glad to see that someone mentioned components containing all nessesary logic stops unnecessary rerendering

  • @ThColinPereira
    @ThColinPereira 2 года назад +3

    whoa, the effects in this video were really cool! great video, pedro!

  • @Colstonewall
    @Colstonewall 2 года назад +12

    Great vid, Pedro! I enjoyed it. . .Just to make a quick point about Fragments in React, the empty tags as you used is the shortcut. In other words, is short for after importing Fragment. Or, just using .
    I know this is a nit picky comment, but some beginners get confused about this. Just mentioning this so others may not get confused about it.

  • @gledianlalushllari9577
    @gledianlalushllari9577 2 года назад +9

    I'm new to react, but my impression was that for single state variables you use useState and for object state you use a reducer. I thought that was the recommendation.

    • @wesleyjanse6600
      @wesleyjanse6600 2 года назад +2

      I think that when you are looking at a state that will only be needed in a certain component you will be looking to use useState, if you are going for a more global state management approach, you could do a setup with reducers and context providers. But if you are new to React, try to understand the basics first and go from there. It's a lot if you try to learn it all at once.

  • @baotruong5775
    @baotruong5775 Год назад +1

    Everything's clear!!! Your voice, your lessons!!! Thank you so much

  • @anazi
    @anazi 2 года назад +2

    Please do not hold on sharing knowledge just because the topic is not "cool enough" or "unique enough." We love you

  • @shafanm
    @shafanm 2 года назад +10

    Hey Pedro, great video as always. Really appreciate all the hard work you put in and the time you are investing in this channel.
    I wanted to add my insight on the "Relationship between States and Objects" subject that you mentioned.
    There is another important consideration that one needs to be aware of when deciding to use a single Object state or split it into multiple single value states as you demonstrated in the video.
    In the case you have a dependency between state's value then it is NOT advisable to split the state, and better to have a single object state or use the useReducer HOOK. This way grantees always get the latest state value. When states are separated you gain performance by letting react decide when is the best time to store the latest state after you set it to its latest value. You may encounter cases where you are checking one state value before settings another state value and you don't necessarily have the latest value since React hasn't set it yet. It's not a common thing usually things happen fast, but on big applications, it can occur.

  • @jccorman5848
    @jccorman5848 2 года назад

    everything that is related to "best practices", clean coding, simplifying is very useful and hopefully not too complicated to make into a video.

  • @galfrano
    @galfrano 2 года назад +1

    good video. quick note on separating states: if you use onsubmit instead, the values change together so it is more concise to keep em together. video idea? react profilers!

  • @catreunion
    @catreunion 2 года назад +1

    Thank you so much!

  • @mabrarhassan
    @mabrarhassan Год назад

    Your video is informative. First topic is new addition to my knowledge and others also help remind me to keep away from mistakes.

  • @jinhu940817
    @jinhu940817 2 года назад

    senangnya menemukan channel sepert ini. terima kasih.

  • @avgSE81
    @avgSE81 2 года назад +2

    Pedro, wiill you please make a video on unit/integration testing?

  • @k303k
    @k303k Год назад

    Thank you for this amazing video PEDRO! You always motivated me to learn more deep dive about React.

  • @emersonjjsouza
    @emersonjjsouza 2 года назад

    Nice tips and tricks from Brazil to World :)

  • @WarframeCrunch
    @WarframeCrunch 2 года назад +1

    Thanks for the first information about rendering.
    Tutorials I watched just shown how to build on react using components, but they didn't mentioned rendering how it exactly works, so in the future I might made mistake of adding useState on the place where many components are so forcing every component to re-render even if they don't have to.
    PropType is also useful before I learn TypeScript.
    Subscribed to you since I just started learning React so I will check other videos later when I end up other tutorials.

  • @mohammedjoubba318
    @mohammedjoubba318 2 года назад +3

    Awesome ! Thank you so much

  • @quofintech9200
    @quofintech9200 2 года назад +34

    Pedro, in a larger project do you usually separate compenents in other folders? Or how do you manage it when it has a lot of components? Thanks!

    • @PedroTechnologies
      @PedroTechnologies  2 года назад +37

      If it is a reusable component like a button or an input, I store it in a components folder. But usually i have a pages folder with a bunch of folders related to each page in my website. I did a video on react folder structures if you are interested :)

    • @mohammedjoubba318
      @mohammedjoubba318 2 года назад +1

      I think he has a video explaining how he separates components

    • @quofintech9200
      @quofintech9200 2 года назад

      @@PedroTechnologies I will take a look, thanks a lot!

    • @quofintech9200
      @quofintech9200 2 года назад +2

      @@mohammedjoubba318 Thanks Mohammed!

    • @Sagora123
      @Sagora123 2 года назад +3

      ​@@quofintech9200 w/ on the job projects, you'll have some hierarchy. Like Pedro said, typically 'pages' has its own separate folder which stores page-level components (Home, Profile, Settings).
      Components can be broken down into a host of multiple sub-directories. Have custom form components? You can create a Form directory, and store form related components:
      * components/form/Button.js
      * components/form/Dropdown.js
      You have several graph components? (PieChart, BarChart, LineGraph) Store it in a folder called 'graphs.
      * components/graph/PieChart.js
      * components/graph/BarChart.js
      File structure and organization is vital when managing large-scale applications.

  • @eliyir
    @eliyir 2 года назад +1

    Thank you, Pedro!

  • @nickwoodward819
    @nickwoodward819 Год назад

    Cool video so far, thanks. Just wanted to quickly comment about your setColor function at 03:16. Should you be using the function parameter of the current color to set the new color?
    A conditional test there looks like it could potentially be based on stale colors

    • @nickwoodward819
      @nickwoodward819 Год назад

      Love these sorts of video though, so please keep making them!

  • @chmodkill
    @chmodkill 2 года назад +1

    good stuff man!

  • @ahmed7253
    @ahmed7253 2 года назад +1

    سوف اكتب هذا بلغتي
    انت عظيم يا فتى استمر في التقدم و الشروحات العظيمة 💪🏼

    • @PedroTechnologies
      @PedroTechnologies  2 года назад +1

      شكرا لك! زميلتي في السكن تتحدث اللغة العربية أيضًا ، لذا أحاول أن أتعلمها :)

    • @masaratech
      @masaratech 2 года назад

      @@PedroTechnologies شكراً لك

    • @Chriss-cn1ch
      @Chriss-cn1ch 2 года назад

      @@PedroTechnologies yallaa

  • @charbouy
    @charbouy 2 года назад +1

    Great video it helps me a lot.

  • @mkgenov3691
    @mkgenov3691 2 года назад +1

    Good advices! Thanks.

  • @itsmeahmedlukman
    @itsmeahmedlukman Год назад

    Wow it's so fascinating to be taught by a university student. Most online lecturers tend to be graduate. I am an undergrad student studying comp scie and am just starting to learn react. Found your tutorials really helpful! Keep up the great work! ❤️

  • @detroit7213
    @detroit7213 2 года назад

    I think for handling big forms useful Is useReducer hook

  • @taharaezell5166
    @taharaezell5166 2 года назад +3

    Awesome information!!

  • @Anonymousmalayali
    @Anonymousmalayali Год назад

    Hi sir please make a video for handling many props drilling.20 or 30 props

  • @demomicrocrawlerclub
    @demomicrocrawlerclub Год назад

    Great video. Useful stuff. Thanks a lot.

  • @Mark-iv5dl
    @Mark-iv5dl 2 года назад +1

    just found out about your channel awesome man! i subscribed

  • @rahuldotel5983
    @rahuldotel5983 2 года назад

    never knew about proptypes thankyou for the exposure 😊😊

  • @wpxpert98
    @wpxpert98 Год назад

    Thanks pedro, its a great video, I enjoy it

  • @nages1549
    @nages1549 11 месяцев назад +1

    Thanks bro ❤

  • @brenoverissimo3846
    @brenoverissimo3846 2 года назад

    Really interesting video. I'm a beginner in React and I think that this sort of video prevents a lot of dirty code along the way. Thanks!

  • @jacobleonhardt4421
    @jacobleonhardt4421 2 года назад

    Thanks for the video! Praying you pass your courses.

  • @connergoldberg
    @connergoldberg 2 года назад +2

    Hey Pedro, would love to see a redux-thunk integration to continue on with your redux-toolkit series! Thanks

  • @NavjotSingh-wo8hj
    @NavjotSingh-wo8hj Год назад

    While propTypes are good for debugging at run time, you really want type checking in place so that you're warned about such issues while you're writing code. That's where you need TypeScript or Flow if your want to incrementally add type safety to your JS project

  • @madhan3658
    @madhan3658 2 года назад +1

    Hey Pedro, thanks for the tremendous video, I was about to learn Proptypes as I am not aware of that, Now I came to an idea of Proptypes, thanks bud!! keep up the good work ❤

  • @chaitanyasawant776
    @chaitanyasawant776 2 года назад +1

    You can make video on how to use Google api with react ( everything related to google api).

  • @dixxixio
    @dixxixio 2 года назад +1

    Thank you for this video! Keep up the good work!

  • @fehmienes5744
    @fehmienes5744 2 года назад

    Hi Pedro. Thanks for the video. I was checking on youtube about how to document your react app with Jsdoc but I didn’t see any videos in good quality. That might be another suggestion if it interests you. Thanks again.

  • @erictan40
    @erictan40 2 года назад

    Like your hustle spirit.... keep going. Thanks for sharing this video.

  • @rawanBairouti
    @rawanBairouti 2 года назад

    This was a fantastic video! Very beneficial and enjoyable at the same time. Keep it up!

  • @vimalswaroopj3429
    @vimalswaroopj3429 2 года назад

    WoW!!! Learnt a lot here :D

  • @samandarjumanov1815
    @samandarjumanov1815 Год назад

    Hey pedro aweome video amazing practice , one whing i wanna mention is can you make a video that best react porjects make us cool at react

  • @hamidr8391
    @hamidr8391 2 года назад

    Please make a video on best practices to organise a bigger project code. Like how to setup layout, routes, pages, components..

  • @playmambo9573
    @playmambo9573 Год назад

    Muchas gracias por los videos. Son excelentes. Estaría muy bien si pudieras hacer uno sobre la arquitectura de proyectos. Cómo empezar desde el diseño del proyecto antes de empezar a escribir código. Existen muy pocos videos de ese tema especializado en React. ¡Gracias por el tiempo que dedicas a compartir tu conocimiento!!

  • @anazi
    @anazi 2 года назад

    Thank you very much Pedro. Your awesome and ypur videos are amazing.

  • @sekhar6753
    @sekhar6753 2 года назад

    can you explain about about which forms can we use, currently i am using react-reative-forms

  • @gabrielmaciel2891
    @gabrielmaciel2891 2 года назад

    Você é Brasileiro né mano? Seu sobrenome entrega kk to aprendendo mto com seus videos. Obrigado por ajudar agnt!

  • @krishnarajasiva9351
    @krishnarajasiva9351 2 года назад

    Hi Pedro.... Can you drop one video for webpack.config.js clear explanation??

  • @adelarsq
    @adelarsq 2 года назад

    Really good tips! Thanks for share!

  • @namucho266
    @namucho266 Год назад

    Can you share the official doc from React team in regards to 9:00 part?

  • @DanielTruongDev
    @DanielTruongDev 2 года назад +1

    Hi Pedro, for the timestamp in the description, if u change the | symbol to a - instead, it’ll automatically add those timestamp in the video ;)

    • @PedroTechnologies
      @PedroTechnologies  2 года назад

      Thank you! For some reason this time it didn't automatically put but the way i did it usually work. But thank you for pointing it out :)

    • @DanielTruongDev
      @DanielTruongDev 2 года назад +1

      @@PedroTechnologies and you also have to add a 0:00 timestamp I believed

  • @Alex.Shalda
    @Alex.Shalda 5 месяцев назад

    Wow! Great video 🎉

  • @johnnymnemonic6703
    @johnnymnemonic6703 2 года назад +1

    Hi Pedro,
    Very informative and nice video.
    Please 🙏 don’t take it as a critique but constructive feedback to make your videos better.
    You are using the mouse to highlight code too much to the point it is slightly distracting even at normal speed.
    I like to watch videos at 1.5 speed and it the mouse highlighting can get very distracting and slightly irritating.
    Try to minimise highlighting with the mouse to the minimum or necessary. For example, the fragment section you were explaining returning siblings you kept on highlighting the tags multiple times but it was already explained that they are siblings.
    I liked the video and really really appreciate the video and please take this as a recommendation and not a critique.

    • @PedroTechnologies
      @PedroTechnologies  2 года назад +1

      Sorry about that hahaha I always try to take criticism as constructive and I appreciate your comment! I do that because I am thinking what I am going to say hahaha but I will try to stop :) I might get like a fidget thing to play with while explaining

  • @aremu_smog
    @aremu_smog 2 года назад

    Any chance you can make a video how to enable PropTypes in Eslint?

  • @lucadifazio2735
    @lucadifazio2735 2 года назад

    Hi Pedro.
    In the third Best Practice, if I make the inputs 2-way-bind to the state, don't both ways violate the first Best Practice?

  • @Aspiiire
    @Aspiiire 2 года назад

    Really amazing content! thank you so much, really useful tips

  • @guilhermedamasceno343
    @guilhermedamasceno343 2 года назад

    Olhei o teu LinkedIn pra ter certeza que é BR. Parabéns, cara. Inglês perfeito e bom conteúdo. Acabei de me inscrever pra te dar uma força também.

  • @NamNguyen-oz8uj
    @NamNguyen-oz8uj 2 года назад

    Very useful Pedro, Thank you very much 🎉🙏

  • @sonamohialdin3376
    @sonamohialdin3376 2 года назад

    Awesome tutorial

  • @vigneshwarrv
    @vigneshwarrv 2 года назад

    hii sir , separating into different component is ideal but what if we want to share state between components.. I mean like having parent component ( form ) with different child component like child1 (inputs for personal data) , child2( inputs for team members ) , child3 ( inputs for work & status updations ) and we need to share those states to parent on submit..

  • @yashiel
    @yashiel 2 года назад

    really helpful stuff thanks

  • @quofintech9200
    @quofintech9200 2 года назад +1

    Great video Pedro, thanks!

  • @GauravYadav-rv7wx
    @GauravYadav-rv7wx 2 года назад

    Can you please tell me what is the performance benefits of splitting the state into name, email and age ?

  • @meetdhanani2174
    @meetdhanani2174 2 года назад

    Great Knowlagable video, Please make more video on NextJs

  • @ivanivan9984
    @ivanivan9984 2 года назад

    I'm not agree with the practice to separate same essence data by difference useState collections.
    I do it only when it is difference essences.
    For example:
    const [wordState, setWordState] = useState({
    name: "",
    translation: "",
    type: ""
    });
    const [modalState, setModalState] = useState({
    show: true,
    text: ""
    });
    Because another way it will be a mess:
    const [wordNameState, setWordNameState] = useState("");
    const [wordTranslationState, setWordTranslationState] = useState("");
    const [wordTypeState, setWordTypeState] = useState("");
    const [modalShowState, setModalShowState] = useState(true);
    const [modalTextState, setModalTextState] = useState("");
    Too many variables, hard to read.
    I also wanted to notice that there is also a good practice common for all programming to name variables the most understandable way. So looking into my example the variable with the name wordState is much clearer than if it could be just word, because word can be only text, it can come as a prop and here you know for sure it's a state var and setWordState is a setter of this var.

  • @hosamgnaba3205
    @hosamgnaba3205 2 года назад

    very useful video man, thank you

  • @konkerouf
    @konkerouf 2 года назад

    man, if you need to split a form state into multiple states to keep it performant, i think there are other parts of your form to optimize.... How big is your form? 2.5M inputs?

  • @mayatundeolawale3
    @mayatundeolawale3 2 года назад

    Can you please build a complete responsive react project with bootstrap and little css

  • @ionut-ciprianandrei5946
    @ionut-ciprianandrei5946 2 года назад

    Could you make a video with stripe for node and react?

  • @hassamulhaq7762
    @hassamulhaq7762 2 года назад

    propsType no more comes with React, need to install separately using npm.
    Predro your performance based and best practices video really helpful. I learnt a lot from this channel.

  • @tanlor
    @tanlor 2 года назад +1

    Fala Pedro!
    Estou estudando e o que me faz decidir ou não aplicar algo no meu projeto é a performance. Por exemplo, no Form que você postou usando e.target.value e setando States faz o componente renderizar, impactando performance, então eu uso a lib ''react-hook-form'' que faz um track dos inputs sem precisar mudar States e renderizar o component, impactando performance. Tem alguma outra lib ou métodos que você prefere usar por conta da performance da aplicação? Faz um vídeo sobre performance! Valeu :)

    • @PedroTechnologies
      @PedroTechnologies  2 года назад +1

      Boa Kleyton, para projectos grandes eu uso a lib Formik. Eu tenho videos tanto sobre formik quanto sobre react-hook-form. Os dois são muito bons! O exemplo no video foi só para explicar mesmo

    • @tanlor
      @tanlor 2 года назад

      @@PedroTechnologies Vou ver o do Formik 🥰

  • @SonAyoD
    @SonAyoD 2 года назад

    Great video!

  • @fuhoo5836
    @fuhoo5836 2 года назад

    just use a form project to handle inputs...
    typescript is a hard requirement.

  • @karis7539
    @karis7539 2 года назад

    10:50 you could just make it as a form and get fields values onSubmit

  • @nikoscuatro7251
    @nikoscuatro7251 Месяц назад

    thanks.

  • @amandinelevecq6664
    @amandinelevecq6664 2 года назад

    Can you make a video on error handling in React please? 😄

  • @arturmavlidov247
    @arturmavlidov247 2 года назад +1

    Thanks!

  • @madihamuhammad3799
    @madihamuhammad3799 2 года назад

    Hi @PedroTech there 2 videos related to Redux toolkit. Basics with redux toolkit and crud also. But for big projects the structure is complicated. there are optional reducers. store is created separate. services also used to get backend data. Have you made any video related to advance redux toolkit ? Or will you have plan to make one? Please reply. Waiting anxiously
    . Thanks

  • @aidenberzins
    @aidenberzins Год назад

    Why not just use a reducer rather than multiple useStates hooks?

  • @stephen7715
    @stephen7715 2 года назад +1

    15:27 "Age is a number" 💀

  • @codewithme2412
    @codewithme2412 2 года назад

    hey pedro what are you using to edit videos ?

  • @f3-faithfitnessfinance
    @f3-faithfitnessfinance 2 года назад +1

    Finally watched your video after a long time 🙌 phewww!!

  • @dev-rachid
    @dev-rachid 2 года назад

    Nextjs tutorial please.
    Thanks a lot 👍

  • @drekforder2952
    @drekforder2952 Год назад

    TS:
    let NAME: TYPE = VALUE
    JS:
    /** @type { TYPE } */
    let NAME = VALUE

  • @davoodsharifi4769
    @davoodsharifi4769 Год назад

    thnks

  • @finkyfreak8515
    @finkyfreak8515 2 года назад

    Good stuff

  • @abhaytiwari6411
    @abhaytiwari6411 2 года назад

    Thanks dude

  • @roman0811
    @roman0811 Год назад

    Why did you make a div with a class of form? Semantically that div could've been a form element to make it PRO :3

  • @jesulobajohn8468
    @jesulobajohn8468 2 года назад

    is not very semantic, thank you

  • @sumitmehra5119
    @sumitmehra5119 2 года назад +2

    To be honest, I knew and implement these steps in day to day development but I still feel like a noob that's why I'm quitting 😂😂

    • @PedroTechnologies
      @PedroTechnologies  2 года назад +2

      DONT QUIT! You are not a noob hahaha we all feel imposter syndrome. I don't consider myself amazing at react, although I know some of my subs probably think I am. It is all about perspective. Just continue learning :)

  • @martapfahl940
    @martapfahl940 Год назад

    Regarding Typescript I would actually disagree and claim that you only need to learn 3 things to cover 90% of typescript use cases:
    - Types
    - Interfaces
    - Generics

  • @andrewaghoghovwia1948
    @andrewaghoghovwia1948 2 года назад

    Thanks Pedro. This was very informative . Please can you do a video on testing custom form inputs? Thanks

  • @matekomenda4706
    @matekomenda4706 2 года назад

    Dude, its really really beginner level that s not gonna make you a pro, so i guess its for students who r getting to know react or javascript or web development.
    But ofc the video could have been useful to others who just started React or idk.

  • @erfelipe
    @erfelipe 2 года назад

    Ótima didática!