How to Improve Performance in React with Code Splitting

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • Hey everyone, in this video I will be going over the concept of code splitting and lazy loading your code in react.
    Join our Discord: / discord
    🚀 Learn ReactJS By Building 6 Projects: codedamn.com/l...
    🐙 GraphQL Course: codedamn.com/l...
    ► Buy Crypto on Coinbase: coinbase-consumer.sjv.io/PedroTech
    Social
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Website: machadopedro.com
    Linkedin: / machadop1407
    Instagram: / _pedro.machado_
    Github: github.com/mac...
    Business Email: pedro@pedrotech.co
    Tags:
    ReactJS Tutorial
    ReactJS and MySQL
    NodeJS Tutorial
    API Tutorial
    #reactjs #codesplitting
  • НаукаНаука

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

  • @arn4v_
    @arn4v_ Год назад +267

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

    • @IdandushHen
      @IdandushHen Год назад +28

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

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

      @@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 Год назад +6

      @@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 Год назад +118

    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.

  • @henrynovoalondono2885
    @henrynovoalondono2885 Год назад +9

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

  • @eshw23
    @eshw23 Год назад +13

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

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

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

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

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

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

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

  • @masj7786
    @masj7786 Год назад +4

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

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

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

  • @pauloluguenda8397
    @pauloluguenda8397 4 месяца назад

    Great content bro, thank you !

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

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

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

    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.

  • @ahmedazizabbassi
    @ahmedazizabbassi 6 месяцев назад

    Thanks! Great Job!

  • @andrewaghoghovwia1948
    @andrewaghoghovwia1948 Год назад +8

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

  • @cutieshakira
    @cutieshakira Год назад +5

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

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

    Great Video bro... helps a lot.

  • @rahulkhatri8304
    @rahulkhatri8304 Год назад +3

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

  • @michaelantoni8323
    @michaelantoni8323 Год назад +6

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

  • @CarolinaNT
    @CarolinaNT Год назад +4

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

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

    Amazing explanation thanks man

  • @anton9410
    @anton9410 Год назад +3

    Great information, thank you for posting this video.

  • @Vedant-M
    @Vedant-M Год назад +1

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

  • @tan2cang93
    @tan2cang93 Год назад +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.

  • @thecyberhobbit
    @thecyberhobbit Год назад +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  Год назад +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 Год назад +1

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

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

      @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.

  • @Goku-zu3rk
    @Goku-zu3rk Год назад +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?

  • @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.

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

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

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

    Nice explanation

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

    As always brother didn't let us down!

  • @Abhisumant03
    @Abhisumant03 Год назад +3

    New react course was damn good 😊😊

  • @jesielpalacios
    @jesielpalacios Год назад +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 ❤

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

    I hate default exports

  • @TheMrtastee
    @TheMrtastee Год назад +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?.

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

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

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

    This is amazing 🥰

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

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

  • @xxvsvitorxx
    @xxvsvitorxx Год назад +6

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

    • @PedroTechnologies
      @PedroTechnologies  Год назад +4

      Vou fazer!

    • @cristhiancunha
      @cristhiancunha Год назад +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.

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

    Please make a playlist -> how to improve

  • @avro-vulcan
    @avro-vulcan Год назад

    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

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

    Vi que você é baiano, pensa em trazer conteúdos em pt-BR também?

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

      Pra ser honesto não! É muito trabalho fazer videos kkkkkkkk Talvez no futuro se fizer sentido, eu podia fazer uns videos e dublar os q eu fiz e postar em português.

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

    I have one doubt ,
    Anyone can explain
    In my company we will only use lazy for popups
    Why we can't use lazy for all components

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

    Gracias Pedro! nuevo skill desbloqueado!

  • @antoniobasilio319
    @antoniobasilio319 Год назад +6

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

  • @jesielpalacios
    @jesielpalacios Год назад +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 :)

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

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

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

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

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

    You can use this npm prettier plugin to sort your imports like a pro
    prettier-plugin-sort-react-imports

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

    Excelente vídeo! Valeu!

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

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

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

    Then NextJs comes to fuck react lol

  • @xesvitinho1231
    @xesvitinho1231 Год назад +3

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

  • @neetugupta8036
    @neetugupta8036 7 месяцев назад

    Thank you! Your video was quite useful

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

    Can we import npm package with react lazy loading?

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

    lol angular does this for years with the lazy module load implementation

  • @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!!

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

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

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

    Please tell me install the app and exucute simple projecr and show

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

    Excellent Video. Pedro, where are you from?

  • @TruthSeeker23-m4o
    @TruthSeeker23-m4o Год назад

    what theme are you using Pedro nice color combination

  • @stressed-ashen-cat
    @stressed-ashen-cat Год назад

    You can also code split packages using react loadable.

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

    Does this affect the app when deploying it?

  • @ZubairKhan-mb6rd
    @ZubairKhan-mb6rd Год назад +1

    Good information on optimisation of a react app.

  • @ayushnigam9424
    @ayushnigam9424 2 месяца назад

    That was amazing, thanks a bunch!!

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

    nice

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

    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?

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

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

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

    Which theme you are using in this video

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

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

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

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

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

    Very usefull man... thanks for share!

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

    awesome video !!

  • @aymenbachiri-yh2hd
    @aymenbachiri-yh2hd 2 месяца назад

    Thank you so much pedro

  • @ronaldomaia
    @ronaldomaia 2 месяца назад

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

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

    Awesome video

  • @jam-trousers
    @jam-trousers Год назад

    Pedantic and possibly wrong of me but I don’t think this is ‘code splitting’ which is more to do with what application packagers like webpack do…

  • @oneofone_1333
    @oneofone_1333 Год назад +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

  • @jpcc1223
    @jpcc1223 Год назад +3

    Ótimo conteúdo, obrigado!

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

    Great video. I think you can better your content by stop saying uhm after every two sentences. Keep up the good work 🙌

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

    Hi Bro good explanation

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

    Awesome video ++++++++++++++ 🙂

  • @GB-vz8pk
    @GB-vz8pk 3 месяца назад

    amazing video!!!

  • @Nick-x4n8x
    @Nick-x4n8x 2 месяца назад

    That is lazy load

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

    Good video! Thank tou

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

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

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

    Great content, congrats

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

    Thank you

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

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

  • @user-xu9tb7oe2z
    @user-xu9tb7oe2z 2 месяца назад

    awesome!

  • @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.

  • @fadyfathey4315
    @fadyfathey4315 5 месяцев назад

    THNX BRO

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

    Please Make video React Multiple Components search please thanks

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

    This is super helpful!

  • @sohrb
    @sohrb 7 месяцев назад

    can you lazy load components from an index file?

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

    Thanks alot

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

    Good point

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

    Great ❤️❤️❤️

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

    Amazing .

  • @golf-and-surf
    @golf-and-surf Год назад

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

  • @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!!!!!

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

    GoodJob!