How to Improve Performance in React with Code Splitting

Поділитися
Вставка
  • Опубліковано 26 гру 2024

КОМЕНТАРІ • 190

  • @arn4v_
    @arn4v_ 2 роки тому +270

    You don't have to export default for dynamic import() to work. You can instead do import('./CreatePort').then(module => module.CreatePost)

    • @IdandushHen
      @IdandushHen 2 роки тому +28

      you actually have to return object with default
      import('./CreatePort').then(module => ({default: module.CreatePost})) - like this

    • @KevinArellano
      @KevinArellano 2 роки тому

      @@IdandushHen you don't have to import/export anything, just have 1 file with 1 line of code and boom!

    • @davidchavarriamendez9091
      @davidchavarriamendez9091 Рік тому

      @@KevinArellano So what's the correct method?

    • @KevinArellano
      @KevinArellano Рік тому

      @@davidchavarriamendez9091 The correct method is up to your case and your boss's case. Can't really choose a "correct" methods when you can do it any way and it works. Now the correct way in my opinion is functionless/serverless architect. Anywhere where microservices can come in and pick up the slack. I absolutely hate when there's a module that either does everything or doesn't do anything at all. Also monoliths are a big no no.

    • @leandrogtabak
      @leandrogtabak Рік тому +7

      @@jameswatadza8962 I don't even know why these people see videos that seem to be so below their level. They just come here to show themselves

  • @torstenmirow
    @torstenmirow 2 роки тому +120

    Actually it's easy possible to use named exports instead of default exports.
    Import function is simply an promise.
    lazy(()=> import('component/login').then(comp => comp.login))
    So no need to change the way you export functions.

  • @CarolinaNT
    @CarolinaNT 2 роки тому +5

    how i leaned so much in a 10 minutes video is out of this world. Thanks Pedro, you're awesome

  • @ramananr3529
    @ramananr3529 Рік тому +3

    Hey Thanks Man!!! Currently I am working on a project where performance is crucial. I am glad I came across this video and applied it on my project. Really helpful content, Have a great day.

    • @tunacant9106
      @tunacant9106 Рік тому

      What is the result like?! I'm so curious, how much performance increase do you see?
      I'm really new to optimising and making it more faster.

  • @cutieshakira
    @cutieshakira 2 роки тому +5

    I didn't know about this concept, thanks for this! also your editing has gotten super clean!

  • @shinobi_coder88
    @shinobi_coder88 Рік тому +1

    Hope you stay healthy as always and keep making these micro-learning videos, it literally helps us to cultivate out mindset of "An Expert is a Beginner who stays actively curious and never quits".
    I like the way you do like, instead of making one long hours big project tutorial, you instead guide us to the basic concepts based on most demanded frontend trends like Performance Optimization and React Hook Form the simplified way. Bravo!!

  • @henrynovoalondono2885
    @henrynovoalondono2885 2 роки тому +9

    Absolutely love these small 10 minute videos. To the point, and learned a whole lot. Thanks

  • @eshw23
    @eshw23 2 роки тому +13

    Yo Pedro amazing video as usual. Good to see your still helping us learn to code while your a software engineer at Twitch!

  • @rahulkhatri8304
    @rahulkhatri8304 2 роки тому +3

    This is definitely increase your website performance.
    I used next/dynamic to import components.

  • @michaelantoni8323
    @michaelantoni8323 2 роки тому +6

    Great performance optimizations, hope you do this kind of videos more.

  • @enriccogemha858
    @enriccogemha858 2 роки тому

    Great vid! I recognized the Brazilian accent as the it started playing 😆
    Keep up the good work!

  • @antoniobasilio319
    @antoniobasilio319 2 роки тому +6

    você é incrível! Merece todo o sucesso do mundo!

  • @MasayaShida
    @MasayaShida 2 роки тому

    I have a mediun sized frontend project and this really helps. Thank you

  • @masj7786
    @masj7786 2 роки тому +5

    I think I've learned from you in a couple of hours more than all these pointless Udemy 40+ hour courses

  • @devmaheremad7360
    @devmaheremad7360 Рік тому

    Ohh, Pedro thanks for sharing this with us thank you so much I love that features, please we need a playlist from things like this, thank you again!!!!!

  • @jonathanorrego6199
    @jonathanorrego6199 Рік тому +1

    Gracias Pedro! nuevo skill desbloqueado!

  • @naveenau143
    @naveenau143 Рік тому

    this is just point to point explanation. Loved it

  • @anton9410
    @anton9410 2 роки тому +3

    Great information, thank you for posting this video.

  • @greimilnunez5179
    @greimilnunez5179 2 роки тому

    Dude your content is amazing, the way that u explain things is really interesting.

  • @marvinfok65
    @marvinfok65 7 місяців тому

    Simply & straightforward! Love the explanation!

  • @rahullingan2119
    @rahullingan2119 Рік тому

    Simple and straightforward explanation! excellent work👏

  • @Abhisumant03
    @Abhisumant03 2 роки тому +3

    New react course was damn good 😊😊

  • @badytouray294
    @badytouray294 Рік тому

    Love this video man :-) well done with the simple explanation

  • @Aakashiyana
    @Aakashiyana Рік тому

    Very well explained in a practical manner

  • @softwaredeveloper2897
    @softwaredeveloper2897 2 роки тому

    I have always wondered how to implement this🤩. Always learning new things from you.

  • @priscillasilva6510
    @priscillasilva6510 2 роки тому +1

    Thank you so much for this video☺You explained it so well

  • @ronaldomaia
    @ronaldomaia 5 місяців тому

    Pedro, seu ingles esta bem fluente! E o seu conteudo e bem apresentado! Parabens!

  • @maxplank1780
    @maxplank1780 2 роки тому +2

    What is the end value of performance you won? Have you calculated it? Or it's just fine thoughts that you read somewhere?

  • @xesvitinho1231
    @xesvitinho1231 2 роки тому +3

    Muito daora mano, manda muito na programação e no ingles tb!!1 brabo

  • @thecyberhobbit
    @thecyberhobbit 2 роки тому +11

    in your example you wrapped the entire Routes with the Suspense... what if like you said you want to only lazy load SOME of those routes... now with the entire Routes block is in the Suspense would that force everything to Lazy load?

    • @PedroTechnologies
      @PedroTechnologies  2 роки тому +16

      The only routes that will lazy load are the ones that you import using the Lazy method. Although they are inside of the suspense, it will only lazy load if you import with the lazy function

    • @thecyberhobbit
      @thecyberhobbit 2 роки тому +1

      @@PedroTechnologies !!! Nice makes sense thanks for the reply!

    • @sajidhssi3445
      @sajidhssi3445 2 роки тому

      @Ajkl Ajkl watch his video from the start and try to understand the the explanation of the purpose of lazy loading. He explained the purpose properly.

  • @jesielpalacios
    @jesielpalacios 2 роки тому +1

    6:35 Actually React Suspense has been used with the same regularity throughout all versions of it's for as long as the hook exists, but it's ok :)

  • @ZubairKhan-mb6rd
    @ZubairKhan-mb6rd 2 роки тому +1

    Good information on optimisation of a react app.

  • @bekiteshome4670
    @bekiteshome4670 Рік тому

    As always brother didn't let us down!

  • @ayushnigam9424
    @ayushnigam9424 5 місяців тому

    That was amazing, thanks a bunch!!

  • @diegopajuelo9060
    @diegopajuelo9060 2 роки тому

    nice man, finally i got it. Thanks.

  • @aldotube88
    @aldotube88 2 роки тому +1

    Nice video, would have been good if you had the code linked in the description also though

  • @pauloluguenda8397
    @pauloluguenda8397 7 місяців тому

    Great content bro, thank you !

  • @jatilyadav4000
    @jatilyadav4000 2 роки тому

    Great Video bro... helps a lot.

  • @Thanveershah
    @Thanveershah 2 роки тому +1

    Jeez the quality ✔✔, What mic do you use?

  • @tan2cang93
    @tan2cang93 2 роки тому +2

    many thanks for your sharing. I have applied react lazy in my project. Howerver, there are so many named export components in project (~ 40-50 files), so I can not go into each Component to change export to export default. Fortunately, I found a package lazily on npm, it works the same as React lazy but will convert named export to default export.

  • @Vedant-M
    @Vedant-M 2 роки тому +1

    Watching Pedro's videos never disappoints. Keep it up 👍🏼👍🏼

  • @dandantin
    @dandantin 2 роки тому

    Excellent Video. Pedro, where are you from?

  • @danhloc112
    @danhloc112 2 роки тому

    It's very useful, thank you so much

  • @RamonBalthazar
    @RamonBalthazar 2 роки тому

    Parabéns mano, muito bom o vídeo 👏

  • @TheMrtastee
    @TheMrtastee 2 роки тому +1

    great video!, is there a way to start loading in the background a lazy component after our normal component renders but before we actually requires the lazy ones?.

  • @baotruong5775
    @baotruong5775 2 роки тому

    Thank you from the bottom of my heart!

  • @andrewaghoghovwia1948
    @andrewaghoghovwia1948 2 роки тому +8

    Hi Pedro..thanks for the invaluable resource. Please can you do a video on design patterns with examples. Thanks

  • @avro-vulcan
    @avro-vulcan 2 роки тому

    i opened a tab in my browser one year ago....on this topic....obviously i lose it among all the hundreds opened tabs 😂. i finally completed my react education...10x

  • @priyabansal9911
    @priyabansal9911 2 роки тому +1

    Please make a playlist -> how to improve

  • @TruthSeeker23-m4o
    @TruthSeeker23-m4o 2 роки тому

    what theme are you using Pedro nice color combination

  • @clickbaitpolice9792
    @clickbaitpolice9792 2 роки тому

    Please 2 questions.
    1) at 6:45 your code just automatically tabbed itself. How?
    2) your tab indents are smaller than mine. How?

    • @Tiagocf2
      @Tiagocf2 2 роки тому

      These are just vscode settings
      1) you can configure it to auto-format the code after you save
      2) his indents are configured to be 2 spaces instead of 1 tab

  • @brilliantatosam
    @brilliantatosam 2 роки тому

    Hey man, I watched this video earlier and loved the concept of lazy loading.
    I am currently implementing it into my current project and am here to ask if lazy loading caches loaded components.
    Thanks, man.

  • @ThColinPereira
    @ThColinPereira 2 роки тому +1

    This is super helpful!

  • @wylakers1250
    @wylakers1250 2 роки тому

    thanks for the vid. I was wondering what theme do you use?
    Thanks

  • @elQueFaltaba
    @elQueFaltaba 2 роки тому +1

    Question, because I can't check it right now. By wrapping Suspense around ALL the links and ALL the lazy loaded components you are forcing ALL of them to be loaded until the menu of links is shown, am I wrong?

    • @PedroTechnologies
      @PedroTechnologies  2 роки тому +1

      No, the menu of links is not lazily loaded and not inside of the Suspense wrapper. It might load first but its independent from the lazily loaded components. Im not sure if I understood the question correctly though so let me know hahaha

    • @elQueFaltaba
      @elQueFaltaba 2 роки тому +1

      @@PedroTechnologies ok, I might have not made it clear (it's midnight here in Spain). Suspense wraps it's children and doesn't show anything other than the Loading component until ALL the children have been loaded, right?

    • @PedroTechnologies
      @PedroTechnologies  2 роки тому +2

      Noo, the suspense will show the fallback if it is triggered. In the case of lazy loading, it will show the fallback whenever one of the components inside of it are loading for the first time. In the video you see that as i switch routes it will show the fallback as long as its the first time i am going to that route

  • @jesielpalacios
    @jesielpalacios 2 роки тому +3

    I'd be great a React crud implementation with Redux and hooks, it's without classes, using containers, slices as well for explain as other ways or cases to use, idk, a tutorial of it without pain ❤

  • @yusufs_solos
    @yusufs_solos 2 роки тому

    Amazing explanation thanks man

  • @Krazness
    @Krazness 2 роки тому

    Great vid bro. Thanks

  • @AlamAmplified
    @AlamAmplified 2 роки тому

    This video explains really well why you should choose angular over react.. 😂😂😂

  • @xxvsvitorxx
    @xxvsvitorxx 2 роки тому +6

    Ótimo video! Poderia fazer um vídeo falando sobre o novo use hook e como isso impactará no React query?

    • @PedroTechnologies
      @PedroTechnologies  2 роки тому +4

      Vou fazer!

    • @cristhiancunha
      @cristhiancunha 2 роки тому +1

      @@PedroTechnologies só vim perceber que era br quando vi os comentários, ótima dicção e ótimo conteúdo, me lembrou bastante a forma como o conteúdo é gerenciado (talvez por debaixo dos panos não tenha nada a ver) pelas páginas agora no Nextjs 13.

  • @davidsyengo1893
    @davidsyengo1893 2 роки тому

    Top notch as usual

  • @salamikhalil9716
    @salamikhalil9716 2 роки тому +1

    Great content 👌

  • @tharindumandusanka7708
    @tharindumandusanka7708 2 роки тому

    Thanks Man ❤❤❤❤

  • @rahulkulkarni9653
    @rahulkulkarni9653 2 роки тому

    This is amazing 🥰

  • @douglasbernardodev
    @douglasbernardodev 2 роки тому +1

    Very usefull man... thanks for share!

  • @rahulkulkarni9653
    @rahulkulkarni9653 2 роки тому

    Please make more videos on how to improve the performance of react application

  • @shubhamdharpure8586
    @shubhamdharpure8586 Рік тому

    Which theme you are using in this video

  • @tadzyla
    @tadzyla 2 роки тому

    Hi Pedro, thank you for sharing tips. I just want to clarify if this can be achieved as well with ? Which is rendering exact route

  • @lilizok4
    @lilizok4 2 роки тому +1

    awesome video !!

  • @jaganvichu
    @jaganvichu Рік тому

    Same problem on my project but I used redux thunk and api calling whenever other pages openings.. so api taking some time for the response.

  • @XeonAlpha
    @XeonAlpha 2 роки тому

    Probably a really stupid question but could you use this same idea to dynamically import a CSS theme to allow a user to select they’re own personalized theme.

  • @EricOnYouTube
    @EricOnYouTube Рік тому

    Pedro, do you have a tutorial on how to auth with Google and then register with an express API app? Thanks.

  • @aymenbachiri-yh2hd
    @aymenbachiri-yh2hd 5 місяців тому

    Thank you so much pedro

  • @golf-and-surf
    @golf-and-surf 2 роки тому

    Why do i blink when i route between pages after adding lazy load?

  • @PurexXD
    @PurexXD 2 роки тому

    Peidro tech sensei. Saludos desde Perú.

  • @ahmedazizabbassi
    @ahmedazizabbassi 9 місяців тому

    Thanks! Great Job!

  • @Saiintss7
    @Saiintss7 2 роки тому

    Is suspense a ready to use and stable functionnality with react ? Because it has been introduced an experimental one for years now

  • @mahammadmansurali7442
    @mahammadmansurali7442 2 роки тому +1

    Can you also make a video on , how to improve performance in Nextjs..please

  • @bofevitaminado
    @bofevitaminado 2 роки тому

    Brabo! Adoro esse canal

  • @apelarealitate
    @apelarealitate Рік тому

    How do you deal with paths that you request form the server and you display the path component in a react bundle? NOT ON A DEV SERVER!! YOU BUILD THE PROJECT AND SERVE IT USING EXPRESS OR WHATEVER. How do you manage that?

  • @eduardohernandezsoto785
    @eduardohernandezsoto785 Рік тому

    I have problem with tailwind css, it's not show css implemented when use lazy

  • @heitortessaro5612
    @heitortessaro5612 2 роки тому

    Great content, congrats

  • @sohrb
    @sohrb 9 місяців тому

    can you lazy load components from an index file?

  • @Untouchable5461
    @Untouchable5461 2 роки тому

    whats your theme font for vscode?

  • @Goku-zu3rk
    @Goku-zu3rk 2 роки тому +2

    What are those curly braces, that appeared after you moved Suspense over Routes?
    BTW: You make very nice Quality-Content. Any ideas what you will do on 100k subs?

  • @TheRavageFang
    @TheRavageFang 2 роки тому +1

    Just don't forget to add error handling in case on poor network lazy loading fails.

  • @russellbanares5324
    @russellbanares5324 2 роки тому

    Does this affect the app when deploying it?

  • @dontscrollitt
    @dontscrollitt 2 роки тому +1

    How can I practice hooks ? I study I understand and after some months I forget. Help me

    • @Joao-oo8yj
      @Joao-oo8yj 2 роки тому +1

      Build your own projects, implementing big functionalities

    • @eshw23
      @eshw23 2 роки тому +1

      Keep building projects and never stop, build more advanced projects after, the hooks will always be needed for every bigger project so you shouldn't forget them, also read up on documentation as well.

    • @tropicaljupiter
      @tropicaljupiter 2 роки тому

      Studying is 10% of learning. Applying is 90%.

    • @PedroTechnologies
      @PedroTechnologies  2 роки тому +2

      I second what they said! Just keep trying to built bigger and more advanced projects and find ways to optimize ur code

  • @nabinsaud4688
    @nabinsaud4688 2 роки тому

    I saw React router documentation v6.4 there is not available old style of doing

  • @raselhossain8855
    @raselhossain8855 Рік тому

    Can we import npm package with react lazy loading?

  • @jpcc1223
    @jpcc1223 2 роки тому +3

    Ótimo conteúdo, obrigado!

  • @softwaredeveloper2897
    @softwaredeveloper2897 2 роки тому

    A quick question. So can one implement code splitting together with the context hook for state management and also use react query at the same time or is that too for performance optimization?

    • @rafaelarantes4804
      @rafaelarantes4804 2 роки тому +1

      I think you are mixing some concepts up. You can have a shared state manager like Context while keeping react-query handling your API calls. You just need to be careful not to mix your shared component state with the react-query state.

    • @softwaredeveloper2897
      @softwaredeveloper2897 2 роки тому

      @@rafaelarantes4804 Thank you for replying. "You just need to be careful not to mix your shared component state with the react-query state." Now this is where I think is messing me upl. Lets say a user logs into a system, where there's route/end point that checks if the "auth" is valid and a route/end point that they use to log in. In such a case, where should the use of both context and react-query come?
      Hope am making sense or maybe I am overthinking the concepts.

    • @rafaelarantes4804
      @rafaelarantes4804 2 роки тому +1

      @@softwaredeveloper2897 You can implement in a number of ways. I'm going to guess your are using a CSR aproach. You can trigger both of your calls using a mutation when you login. Either, changing some local state that is a dependency of your useQuery or refetching it using the imperative property refetch that you can destructure from useQuery. Idealy, this component should be a wrapper over , that you can use as a component.

    • @softwaredeveloper2897
      @softwaredeveloper2897 2 роки тому

      @@rafaelarantes4804 Wow!! thanks a ton💪. It's like you were reading through my code. I really appreciate you taking your time to help. It means a lot. How can I reach out incase of anything?
      Regards

  • @Lichkuroro
    @Lichkuroro 2 роки тому

    will this work on next js?

  • @Monstermash355
    @Monstermash355 2 роки тому

    Is suspense really recommended in a actual large scale application ? It's still experimental...

  • @sillasbernardodev
    @sillasbernardodev Рік тому

    Nice explanation

  • @stressed-ashen-cat
    @stressed-ashen-cat 2 роки тому

    You can also code split packages using react loadable.

  • @oneofone_1333
    @oneofone_1333 2 роки тому +4

    Yo Pedro love your content always, huge inspiration.
    Quick question, is it normal that am having more fun and actually building stuff in react js and not vanilla js? As soon as i learned the basic in vanilla js, i moved on to react and no am a bit worried that i didnt spend enough time in learning everthing in JS and building projects. Hope it makes what i just wrote😂. Greetings from Switzerland

  • @bhumit070
    @bhumit070 2 роки тому

    so it does not work with named exports ?

  • @RonnieryBorges
    @RonnieryBorges 2 роки тому

    Mano seu Inglês está brabo congratz.

  • @NooblantisDistrict
    @NooblantisDistrict 2 роки тому

    not applicable to next js right?