6 Pro Tips from React Developers

Поділитися
Вставка
  • Опубліковано 6 лют 2025

КОМЕНТАРІ • 302

  • @surajvijay1937
    @surajvijay1937 3 роки тому +10

    0:21 - "Use functional components" - Cam Jackson
    0:58 - "Keep your components small" - Randy Coulman
    2:15 - "Understand how to handle 'this'" - Cory House
    4:00 - "Use a function in 'setState', not an object" - Sophia Shoemaker
    4:38 - "Utilize prop-types" - Adam Jahr (None other than the guy who made this video)
    5:11 - "Use React Developer Tools." - Brian Gates

  • @modinaleksey4073
    @modinaleksey4073 5 років тому +28

    Pro tip: don’t try to create large reusable components, in one day you will find yourself trying to understand what happens there. Only small components like buttons, inputs and other parts of interface can be really reusable.

  • @arhabersham
    @arhabersham 6 років тому +9

    This video is BEAUTIFULLY illustrated, + the voice cadence background music separates it from the monotone style of others. The content is so relevant, and illustrations are INCREDIBLY useful and beautiful. Great job!!!

  • @artemmakatera8663
    @artemmakatera8663 6 років тому +161

    One useful tip.Never use use index of array as a key when you map data to list. It is better to use unique id as a key. Because if you need to add new element as a first element. React will compare it with previous key and react won't see the diiference between items and won't rerendered items with similar keys in similar place. If you need to create new list item before saving to server it' woul'd be better to use uuid or something else to create temporary fake id(for ex. `fake_${uuid()}`).

    • @yevhenkozlov286
      @yevhenkozlov286 5 років тому +9

      nope. key is only about update-vs-recreate difference(performance thing). so in case mentioned when you insert element into 0 position it will lead all elements are updated. while if using meaningful "key" only element just added will be rendered(and all other will stay untouched). there will be never a case 'won't rerendered'

    • @nageshwarreddy4530
      @nageshwarreddy4530 5 років тому +2

      You can also use Date.now() as key

    • @vickylance
      @vickylance 5 років тому +7

      @@nageshwarreddy4530 That doesn't work because Date.now() will be the same for all the items in the list. Computers are fast :)

    • @vickylance
      @vickylance 5 років тому

      @@MikeCOYS If you get id from the response data then it's well and good. But there are places where you don't have the id or you don't even make an API call you just iterate over some generated data.

    • @f.k.1484
      @f.k.1484 5 років тому

      Issues would come with sort anyways so an id or a way to uniquely identify is always an option depending on the exact requirement

  • @AlanDarkworld
    @AlanDarkworld 6 років тому +3

    Nice video. The most important tip that I can provide for react devs: use TypeScript. Always. All the time. It will prevent so many potential errors.

    • @jmcauhy
      @jmcauhy 5 років тому

      I'm starting to learn React now, do you think I should learn it with TypeScript already?

  • @KazSadeghi
    @KazSadeghi 6 років тому +1

    There's another version of setState where you pass in a callback that should be called when the state has actually been updated. the first argument is the state update, the second is the callback.
    This allows you to change very little code from the version that only has an update, merely passing in what the function should do afterwards.
    For more information of this kind of async programming, see Continuation Passing Style.

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

      You're right , however it can crash when you have multiple setState's, as you don't know which finishes first. Creating the arrow function before the render is the least problem-causing way .

  • @danielkhoroshko4422
    @danielkhoroshko4422 6 років тому +157

    At what minute do the pro tips start?

  • @hannad
    @hannad 6 років тому +132

    Use function in setState only when state update requires prev state. Otherwise use object in setState

    • @nhulongctk10
      @nhulongctk10 6 років тому +8

      not really. setState is a async function. some case we need to use function in setState

    • @handleOfThy
      @handleOfThy 6 років тому +2

      I see you are a man of culture, rocking that Opeth tee

    • @sergiogusto
      @sergiogusto 5 років тому +3

      this.setState has a callback function. In this callback, the state is the data is exactly updated. So then you can do all that you need with actual data from the state.
      example: this.setState({ id }, () => console.log('do something with this.state.id') );

    • @f.k.1484
      @f.k.1484 5 років тому

      Also this is Syntax only. Syntax is like the most basic tools you should be able to handle in order to move to patterns and then write clean reusable code imo

    • @marcpeace204
      @marcpeace204 5 років тому

      Thanks.

  • @lexsoft3969
    @lexsoft3969 6 років тому +5

    Tip 7 : get ready for Hooks, the upcoming feature that will solve existing problems according to React team. It will probably mean that we will say goodbye to classes esp when creating new codes.

    • @gracewood6768
      @gracewood6768 4 роки тому

      When i used that. wow , it became clearner! as a begineer reactjs programmer, that made my life easier, but my projects were all into oldies, so i had problems on adapting the classic react thingy

    • @thefakedeal
      @thefakedeal 3 роки тому

      I learned react after hooks were introduced, so I never even learned class components

  • @RealRurik
    @RealRurik 5 років тому +11

    Don forget to use hooks to keep it even more simple, it didn't mention it because the video is old :).

  • @samirmahmudlu
    @samirmahmudlu 4 роки тому

    Thank you so much. Can u do next video about prevent additional ( not required) rerendering? Please.

  • @platek549
    @platek549 4 роки тому +1

    When should you use class based components instead of functional components

    • @lordcheetos
      @lordcheetos 3 роки тому +1

      They're just old, and less updated

  • @bharathprakash410
    @bharathprakash410 5 років тому +6

    React hooks is the best option 😍 for the functional components.

  • @IgorBrandao
    @IgorBrandao 6 років тому +2

    Great tips, and to add on tip #5, you can use this.state after this.setState as long as you use its second parameter which is a callback function that gets called when the state is set.
    this.setState({ someFlag: true }, () => this.state.someFlag ? console.log('isTrue') : console.log('isFalse')) // will print 'isTrue'

  • @ShanjaiRaj
    @ShanjaiRaj 4 роки тому

    With headphones, this video looks perfect

  • @innovationscode9909
    @innovationscode9909 4 роки тому

    Just use Typescript insteqr of prop-types. It will help you prevent type errors over all...not just in props...

  • @ychinamale
    @ychinamale 4 роки тому

    @Vue Mastery what software do you use for the animations on your code snippets? e.g. from 1:37 to 2:11

  • @wise_nut
    @wise_nut 6 років тому

    This is all I've wanted to know about since I'm stuck on my project........ ....... thanks Adam!!!!!!!! your voice's so good

  • @ashishrathi9600
    @ashishrathi9600 3 роки тому

    Nice content, I liked tip 4. Thanks for sharing

  • @JD-ug9gv
    @JD-ug9gv 5 років тому

    well done. short, sweet, informative. bongos were a little distracting

  • @borisangelov44
    @borisangelov44 4 роки тому

    Very nicely said! Good work. Just one note - React is a library.

  • @devmrin
    @devmrin 6 років тому

    For cases when you need state - however don't need your stateful component to rerender - shouldComponentUpdate is a GODSEND! It alone will improve your apps performance many fold!

  • @dandogamer
    @dandogamer 6 років тому +2

    I've been using react for less than a week and use all these tips :)
    Ps. Still prefer angular over react

    • @JBuchmann
      @JBuchmann 5 років тому

      5 months later, do you still prefer Angular? Just curious because I'm an Angular guy who recently is getting into React

  • @mihirvaghela3479
    @mihirvaghela3479 4 роки тому

    Nice video, more than I expected

  • @Amin52J
    @Amin52J 6 років тому +83

    These are some basics you need to learn before jumping into a project, so they're not pro tips. :-|

  • @sachinjasrotia2279
    @sachinjasrotia2279 7 років тому +5

    great idea to explain the tricks....quick fast and effective way....thanks bro....

  • @nlgachu7536
    @nlgachu7536 4 роки тому

    Use promises instead of callbacks. Use async/await keywords.
    I believe all custom functions/methods should be async by default to avoid potential unnecessary refactor in future. Dont know about possible performance issues.
    Use Immer library to update complex state by simply overriding object property.

  • @jorox8948
    @jorox8948 5 років тому +2

    logMessage=()=>{
    //blablabla
    }
    works without binding 3:15

  • @dcairol
    @dcairol 5 років тому

    Good tips! Tip #5 not needed of you use Typescript

  • @vaghelabhavin
    @vaghelabhavin 6 років тому

    Tip 4 is literally a PRO Tip.
    Thank you.

  • @VishnuASankaran
    @VishnuASankaran 6 років тому +1

    Using a functional component may not be a good choice if you consider the rendering performance. The component re-renders every single time, its parent re-renders. So, I would recommend using React.PureComponent for smaller components which has primitive prop types.

  • @neihe25
    @neihe25 6 років тому

    In addition to tipp five you don't need to use proptypes another way is to use interfaces for props and even for the state maybe it is something worth to mention.

  • @neihe25
    @neihe25 6 років тому +1

    Does the avatar class at 2:07 really work? Because you insert as prop props.user and then you want to access props.user.name. Wouldn't it result in can not read property of undefined? Because you should use props.name??

    • @tjgxxx
      @tjgxxx 6 років тому +1

      No. The Comment component is passing the user object to the UserInfo component and the UserInfo component is passing the same user object to the Avatar component so Avatar has access to the user object that has a property 'name'.
      props does not become the user object. props is an object that has the user object as a property. does that make sense?

    • @seanflanigan7
      @seanflanigan7 5 років тому

      @@tjgxxx Thanks. I had to write out the avatar code sample to understand it: jsfiddle.net/3tcxjof1/

  • @user-hg5qh3ni3f
    @user-hg5qh3ni3f 5 років тому

    Awesome tips for a beginner like me. thanks

  • @MD-xx6ob
    @MD-xx6ob 6 років тому +1

    prop-types is useful but i prefer to use a superset of JS like typescript to declare component props using interface

    • @lexsoft3969
      @lexsoft3969 6 років тому +1

      Great. Typescript should be the future of client-side scripting. It seems that you have been successful in using typescript in React.

  • @pramodjodhani
    @pramodjodhani 6 років тому

    Which software do you use to edit the videos?

  • @HostDotPromo
    @HostDotPromo 4 роки тому

    Time to learn react more in 2021

  • @andrazkos8309
    @andrazkos8309 6 років тому +1

    Stop using setState for anything but internal micro-state of the GUI (for example: input has value state, when onChange triggers, you should copy this internal value state to the proper place into the real store). This way you keep the performance. For everything else, use mobx-state-tree (MobX upgraded into a structure to make it as robust as redux without the useless boilerplate and copy pasting of redux). Then you just trigger (onChane) an action directly on the store with value as the parameter -> gets written to the store, then automatically updated in the GUI (by simply wrapping the functional component into a mobx-react observer).

    • @rallokkcaz
      @rallokkcaz 6 років тому

      Andraž Kos I was leaning towards mobx for React dev but this sounds interesting.

  • @eugenhildt910
    @eugenhildt910 6 років тому

    If you have a template (functional component) then just pass through the props. Let the template decide what you need out of props. Also use Redux. With Redux you won't ever need to deal with setState.. well mostly. React + React-Redux + Redux-Act = Your best Friend.

    • @rallokkcaz
      @rallokkcaz 6 років тому

      Eugen Hildt redux is hell.

  • @RomanOstolosh
    @RomanOstolosh 6 років тому

    Can I use static methods od a class to define prop types instead?

  • @EdgieMan
    @EdgieMan 7 років тому +3

    Hello. Thanks for sharing. I have a question regarding tip No.1 and all others. You recommend to use functional components, but using React classes in the following tips. Could you clarify when it is necessary to use classes if at all, and how to manage data within an app if not through states?

    • @leonardocosta6038
      @leonardocosta6038 6 років тому

      Eduards V He recommends using functional components when the component is stateless. One of the best ways to manage state is by using Redux.

    • @BBQGaming69
      @BBQGaming69 6 років тому

      or if it doesn't use life cycle methods

    • @HanYou2
      @HanYou2 6 років тому

      Use functional components when you don's store data on this.state and only use the received props. Usually stateful components are called 'containers', and stateless components are called 'components'. You use the containers for state management. Redux is a big higher order components which does state management.

  • @mohouyizme
    @mohouyizme 7 років тому +3

    Useful information. Thanks!

  • @burakselvi4515
    @burakselvi4515 5 років тому +2

    The Vue channel's most viewed video is about React :)

  • @CPlayMasH_Tutoriales
    @CPlayMasH_Tutoriales 6 років тому

    I see the point of functional components, but I prefer extending from PureComponent in favor of performance

  • @vishal_taywade
    @vishal_taywade 5 років тому

    You shared very useful tips.. 👍
    We'd like to see more such of..
    Thanks

  • @RobertBrunhage
    @RobertBrunhage 6 років тому

    Great video! What program did you use to animate and write out the code?

    • @VueMastery
      @VueMastery  6 років тому

      Thanks! Animations are done in Keynote.

  • @JAdamMoore
    @JAdamMoore 6 років тому

    This was a very well done video. You should be proud.

  • @jerryjeremy4038
    @jerryjeremy4038 6 років тому

    I just subscribed! I am very new to reactjs and i want to start at the correct way. Thanks

  • @MisterCuriusController
    @MisterCuriusController 5 років тому +41

    wait why a video about react in this Vue channel?

    • @farzadsole3784
      @farzadsole3784 5 років тому +1

      Good 1 :P
      But that's their company name LOL

    • @geovannyrios6751
      @geovannyrios6751 4 роки тому +1

      same question

    • @MisterCuriusController
      @MisterCuriusController 4 роки тому

      @@farzadsole3784 oh I see, Im not angry or hate react or vue. Im just curios why.. So Vue and React are the same company?

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

      ​@@MisterCuriusController Vue and React are both front end frameworks that allow developers to more easily build complex apps. While they accomplish the same objective, the two have different approaches and techniques, so looking at what people are doing in react can give vue developers new ideas/perspectives.

  • @jaimenoelalvarezluna3500
    @jaimenoelalvarezluna3500 6 років тому

    if only I had seen this video when I started with react everything could have been different. I've worked with React for a year and 5 months, I learned this tips and some "good practices" by try and error.
    Now with getDerivedStateFromProps it became a little bit tricky because nobody had establish a good practice.

  • @manafront
    @manafront 4 роки тому

    do you have a course? im in lambda and react is really making me nervous

  • @oficialdesigner
    @oficialdesigner 7 років тому +2

    Thanks, it's really helped me now!

  • @IntelsCreed
    @IntelsCreed 4 роки тому

    Nice ! Important tips...but I don't know if they are pro tips !

  • @RagazzoKZ
    @RagazzoKZ 6 років тому +3

    How to pass arguments to function in case 3:30 ???

    • @DucHong
      @DucHong 6 років тому

      at @3:30 case, it's a case when logMessage doesn't require args, in case you do, simply write arrow function in onClick props, something like onClick={() => this.logMessage(arg1, arg2 ....)}

    • @RagazzoKZ
      @RagazzoKZ 6 років тому

      In this case it creates a new function for each rendering, that's no good, But I don't see any idea for workaround that.

    • @oleksandrkryvosheiev4915
      @oleksandrkryvosheiev4915 6 років тому

      @@RagazzoKZ you can write like
      logMessage = (args) => () => {
      ···
      }
      And in render method
      this.logMessage(args)

    • @kurororushirufuru2850
      @kurororushirufuru2850 6 років тому

      *EDIT:* My apologies for the heads up.
      I think it would be the same as a regular function.
      For example:
      logMessage = (message) => {
      console.log(message);
      }
      Then in render method:
      { this.logMessage(message) }
      *NOTE:* In Babel, you may need the package *@babel/plugin-proposal-class-properties* to transform arrow functions inside classes.

    • @frankrodriguez6021
      @frankrodriguez6021 6 років тому

      If you want to pass arguments to a function the best way to do it is by using props of the component.
      You can checkout this gist to see an example: gist.github.com/frankrod/4e3c01fb2f8f20b3ca0474ec512dece7

  • @erickgeneric
    @erickgeneric 4 роки тому

    I’m confused. I thought you could use state (useState) in a functional component. What am I missing

    • @Eelmascapito
      @Eelmascapito 4 роки тому

      Thats a hook

    • @137dylan
      @137dylan 3 роки тому

      Video was made in 2017. useState (hooks) were released in 2018.

  • @KunglawAdy
    @KunglawAdy 4 роки тому

    3.02 really you dont need bind that function ?? woooww i need to try it

  • @prakashale1627
    @prakashale1627 5 років тому

    Great tips for beginners

  • @KajiTetsushi
    @KajiTetsushi 7 років тому +34

    Nice! I use all of these tips on a daily basis, *except* #4 (3:58).
    I didn't know functions in _this.setState_ was a thing. The no-guarantee of instant state change is because _setState_ is asynchronous, right?

    • @VueMastery
      @VueMastery  7 років тому +6

      Yep that's correct!

    • @hyoukuriyama1071
      @hyoukuriyama1071 7 років тому +1

      now, i know!

    • @rayane4975
      @rayane4975 6 років тому

      I tried callback and functions but its still asynchronous ... :/

    • @sugarlife1246
      @sugarlife1246 6 років тому +1

      medium.com/@voonminghann/when-to-use-callback-function-of-setstate-in-react-37fff67e5a6c Check this article and you'll get it!

    • @sayamqazi
      @sayamqazi 6 років тому

      finding out about that function in setState was the best thing for me.

  • @MrLarryQ
    @MrLarryQ 7 років тому +18

    Great stuff here. May I ask what video editing software you used, your transitions and code transformations/code splitting are very professional.

    • @VueMastery
      @VueMastery  7 років тому +11

      Thank you :) A combination of Keynote and Screenflow were used to create this video.

  • @niyacodes
    @niyacodes 6 років тому

    With react hooks (like useState) the .this boilerplate is going to be a thing of history.

  • @NoName-j8j3o
    @NoName-j8j3o 5 років тому

    Very helpful video!

  • @ThiagoTAV
    @ThiagoTAV 7 років тому +2

    Very good tips, thank you.

  • @irasanchez1265
    @irasanchez1265 5 років тому

    Knowing when to break things apart and not get too carried away is tough for me.

  • @TheYari1210
    @TheYari1210 5 років тому

    Wow! Amazing tips... Great vid thanks!

  • @ankurgupta2936
    @ankurgupta2936 3 роки тому

    But after hooks , they recommend to use functional components instead of class components. Isnt that true?

  • @thisaintmyrealname1
    @thisaintmyrealname1 6 років тому +1

    Great video man!

  • @marvinandia1214
    @marvinandia1214 6 років тому +142

    Mmm i don’t know if these are “pro” tips

    • @tjgxxx
      @tjgxxx 6 років тому +11

      yah these definitely seem pretty standard and also opinionated.

    • @MikeCOYS
      @MikeCOYS 5 років тому +2

      They’re more “common sense” than pro tips. It depends on the situation to use what’s best, but he makes it sound like you should only use the one he points out.
      One example perhaps he should also list the disadvantages but he doesn’t mention any. Arrow class functions is good but not so much when you’re trying to mock it in a test.

    • @totalolage
      @totalolage 5 років тому

      I've literally been a react dev for 10 days, having never used it before that, and I've figured out all but functional components and functional state set on my own. I was looking to improve, not be told what every tutorial tells you.

    • @franciscoayala6923
      @franciscoayala6923 5 років тому

      do you have another alternatives to "pro" tips? :)

  • @pokegaiyui
    @pokegaiyui 6 років тому

    This was super useful!!

  • @rohitpatil3679
    @rohitpatil3679 6 років тому

    Can I get some documentation on this ? It would be really helpful

  • @naveed-h
    @naveed-h 5 років тому +8

    Who cares about the video when the music so damn good. I'm dancing sice like forever!

  • @mattmarkus4868
    @mattmarkus4868 6 років тому

    Does VueMastery have React training too then?

    • @VueMastery
      @VueMastery  6 років тому

      We made this video before we chose to focus exclusively on Vue.js :)

  • @hyoukuriyama1071
    @hyoukuriyama1071 7 років тому +2

    thanks brother for the tips! good video!

  • @monsieurm2904
    @monsieurm2904 4 роки тому

    Hello, thank you for your tips !

  • @eduardonakanishi
    @eduardonakanishi 6 років тому +4

    Nice vídeo, but most of the pro tips van be found on the “FUNDAMENTALS” section of the react docs

  • @aaron___6014
    @aaron___6014 4 роки тому +1

    For number 2, say you never end up using the 3 smaller components that you extracted out of the 1. Isn't this just complicating things in order to follow React 'rules'? You have code spread across 3 components (files) now instead of 1.

  • @_JocelioLima
    @_JocelioLima 5 років тому

    Hey, do you have some tip about using something like proptypes for react context api?

    • @sergiogusto
      @sergiogusto 5 років тому

      use Redux. Bytheway, to make your code cleaner you can use this import { string, number, func... } from 'prop-types;'

  • @moloodayat6039
    @moloodayat6039 5 років тому

    Greate tips 👍👍👍

  • @-ejs-
    @-ejs- 6 років тому

    Hey thanks for your tips!. I'm kind of new into the react world and i'm having a little bit of trouble with components and functional components. I'm using redux to handle application state but the problem is that every time an action gets called, all child component gets rerendered and it's causing me some performance issues. I solved this by using pure components to avoid unnecesary renders but i don't know if there's a cleanner way to handle it. What do you think, is there a better solution?, because almost every post i read it says that i should stay away from pure components but no idea why. Thanks!

    • @golfmc7941
      @golfmc7941 6 років тому

      Emilio Jeldes I am more of a vue person but it sounds like you may need to key your child components.

  • @rammaheshwari3008
    @rammaheshwari3008 6 років тому +1

    Great Information

  • @returnZeroo
    @returnZeroo 5 років тому

    How did you made these presentations?
    Can you give me suggestion please?

  • @ahsanusman3993
    @ahsanusman3993 6 років тому +1

    awesome work!

  • @MosesMatsepane
    @MosesMatsepane 6 років тому

    Great stuff bro! Thanks!

  • @jugnush
    @jugnush 5 років тому

    what music is playing in BG ?

  • @edinpuzic
    @edinpuzic 7 років тому +1

    Tip 3:
    You can install babel plugin transform class properties (babeljs.io/docs/plugins/transform-class-properties)
    then you don't need to bind this in ES6 classes. Right?

    • @VueMastery
      @VueMastery  7 років тому

      You can utilize that plugin to define properties inside of class definitions themselves as static class properties. Don't forget to update your .babelrc file with that plugin.

  • @tronguctran1433
    @tronguctran1433 5 років тому

    thank for video ,
    It is very useful

  • @davidscarios
    @davidscarios 6 років тому +1

    Very usessful, Thanks

  • @csanadtemesvari9251
    @csanadtemesvari9251 6 років тому +4

    Now you know how to React.

  • @hichdima
    @hichdima 5 років тому +1

    is functional components advise still relevant in 2019?

    • @Yetipfote
      @Yetipfote 5 років тому +1

      Yes. But now you can scrap the "if you don't need life cycle methods" part, because via hooks there are possibilities to emulate life cycle methods easily.

  • @elmapaul2791
    @elmapaul2791 7 років тому +2

    U've made my day!

  • @azizas9366
    @azizas9366 6 років тому

    Thank you for the video. I have been looking for something like that.
    Can you do a video :) on when to use create-react-app VS using webpack?

    • @golfmc7941
      @golfmc7941 6 років тому +3

      aziz as CRA is great for beginners. If you just want to do something that can be done with a template, or want to make something quickly, then go ahead. When you learn more about webpack and other tooling its worth doing something else. Maybe try ejecting from a CRA app, or try making your own configuration.

  • @Spoolie
    @Spoolie 6 років тому +1

    1:56 that in my opinion is part of what's wrong with react "developers". That is poor code. You've now coupled your 2 "reusable" components to the data structure and it is no longer very reusable at all. Just because you can write code doesn't make you a developer. Think about the long term effect of things you do and you'll avoid poor code like that.

    • @gab_shirohige
      @gab_shirohige 5 років тому

      I know it's a bit late but.. WTF are you talking about? The 2 components that he separated is still reusable. You had a monologue of how "bad" are the other developers yet you didn't explain shit. People like you are toxic to work with.

  • @fideltorres399
    @fideltorres399 5 років тому

    Props-types, what about Typescript instead?

  • @BuddikaChaturanga
    @BuddikaChaturanga 5 років тому

    Use object destruct pattern
    Use default valuse library

  • @tim_t
    @tim_t 6 років тому

    Thanks, Justin.

  • @rckd5903
    @rckd5903 6 років тому

    PureComponent > Stateless components in terms of performance. The latter will be re-rendered every time the parent changes.

    • @vzsshadow3141
      @vzsshadow3141 5 років тому

      stackoverflow.com/questions/53446020/how-to-compare-oldvalues-and-newvalues-on-react-hooks-useeffect

  • @HostDotPromo
    @HostDotPromo 6 років тому +3

    Pretty good tips, I personally prefer Vue.

  • @asdfkerub
    @asdfkerub 7 років тому +3

    tip 4 got me confused. Does this actually change the state key value? Why does is seem like your just changing the key value to its previous value? Also, what is the use of props parameter if it not being used? Sorry im a bit confused here and this seems like a useful thing to know.

    • @asdfkerub
      @asdfkerub 7 років тому +1

      Also, will tip 4 work if you are completely changing the key value?

    • @hrafars91
      @hrafars91 6 років тому +2

      You can do like so:
      return {...previousState, toUpdate: props.whatYouWant}
      Then you ensure you only change what you want and let the remainder of the state be whatever it might become.

    • @CoryTheSimmons
      @CoryTheSimmons 6 років тому

      Here's a really simple demo with some comments. codesandbox.io/s/32kznjxkx6
      If you do React dev for a while you'll 100% run into wanting to adjust state AFTER some other state has been modified, and the setState(prevState => (...)) thing is a really convenient way to do it.
      Regarding the signature, setState can accept a POJO, or a function that returns a POJO.

    • @MrJasonFrank
      @MrJasonFrank 6 років тому

      Thanks for that demo Cory!

    • @HanYou2
      @HanYou2 6 років тому

      ​@@CoryTheSimmons For this specific case, updating state after another state update, it's good to know that setState also has a callback function, to be sure the previous state changes are already applied:
      // this.state.toChange === 1
      this.setState(
      (prevState, props) => ({ ...prevState, toChange: prevState.toChange + 1 }),
      () => {
      this.setState((prevState, props) => ({ ...prevState, toChange: prevState.toChange + 1 }))
      },
      )
      // this.state.toChange === 3
      -> but if you do this too much, you run into callback hell

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

    Pro Tip - Never use
    "npx create react app" instead use
    "npm create vite@latest"
    To create an react application

  • @nlgachu7536
    @nlgachu7536 4 роки тому

    refactor unnecessary arrow functions to class methods to minimalize memory leaks
    Do not modify props directly. Can cause performance issues.
    Do not use service container. Import your services directly from file where export is defined. E.g.: "export const myService = new MyService();"
    Globalize your component state using Redux.

  • @matheustavares4442
    @matheustavares4442 4 роки тому

    i mean, pro tips because he's a professional developer??
    because i'm started react about 4 days now, and just for reading know most of it
    but, i should say, it's a great video