How to pass data between sibling components in React | Lifting up state | Easiest way

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ธ.ค. 2024

ความคิดเห็น • 32

  • @exacode
    @exacode  ปีที่แล้ว

    I hope you enjoy watching it as much as I enjoyed making it. If you have any questions or comments, feel free to leave them below and I'll do my best to respond. And don't forget to like and subscribe to my channel for more great content!

  • @sumanshuborkar5788
    @sumanshuborkar5788 ปีที่แล้ว +3

    As a beginner in react this method is really useful to me , thanks brother!

    • @exacode
      @exacode  ปีที่แล้ว

      Glad it was helpful!

  • @dbuddheiejsjejebwiwhww
    @dbuddheiejsjejebwiwhww ปีที่แล้ว

    Bro it feels so freaking easy after your explaination... Thank U... I had a huge confusion here.. And U just cleared it... Thank U again❤

  • @ademuwagunoladipupo1188
    @ademuwagunoladipupo1188 11 หลายเดือนก่อน

    Thank you. I am new to Rect.js and this video helped me solve my assignment

  • @semistrunniysamurai
    @semistrunniysamurai ปีที่แล้ว

    Thank you for the lesson!!!!

    • @exacode
      @exacode  ปีที่แล้ว

      Glad it was helpful!

  • @patel5532
    @patel5532 7 หลายเดือนก่อน

    I've same use case but in my case I need to pass only 2 props value (username and password) out of bunch of state values from my one sibling to another.

  • @SonuSinghmirzapur
    @SonuSinghmirzapur ปีที่แล้ว

    Code for Expo = React native ?
    Are both same ?

  • @adil3344
    @adil3344 ปีที่แล้ว

    very good explaination

  • @samthetutor
    @samthetutor ปีที่แล้ว

    Amazing video 🤝🤝🤝🤝

    • @exacode
      @exacode  ปีที่แล้ว

      Glad it was useful!

  • @roshantambe-bu7st
    @roshantambe-bu7st 4 หลายเดือนก่อน

    nice video...❤❤

  • @bapandas1746
    @bapandas1746 ปีที่แล้ว

    Osm video sir nice explain

    • @exacode
      @exacode  ปีที่แล้ว

      Glad it was helpful!

  • @dineshsinghbisht07
    @dineshsinghbisht07 2 ปีที่แล้ว

    Very Helpful Thanks Sir🔥❤

    • @exacode
      @exacode  ปีที่แล้ว

      Glad it was helpful!

  • @MohammedZaid-u2g
    @MohammedZaid-u2g 11 หลายเดือนก่อน

    Thank you

  • @Free_Bird78
    @Free_Bird78 ปีที่แล้ว

    nice explanation
    👍👍

    • @exacode
      @exacode  ปีที่แล้ว

      Glad it was helpful!

  • @alanhf
    @alanhf 11 หลายเดือนก่อน

    But lifting state won't cause a rerender of the parent component?

    • @exacode
      @exacode  11 หลายเดือนก่อน +1

      Yes, when state is lifted up to a parent component in React, changes to that state can trigger a re-render of the parent component. This is because when the state is updated, React will re-render the component and its children to reflect the new state.

    • @alanhf
      @alanhf 11 หลายเดือนก่อน

      @@exacode So... is it possible to prevent this full rerender without advanced state management? I've been banging my head against this wall for a while. Thank you!

    • @exacode
      @exacode  11 หลายเดือนก่อน

      @alanhf I think you can make the child components pure component using React.memo() that will stop the pure component being re-render if the props for that component are not changed.
      However the parent component will still re-render ( since state is changed in parent) and its all the non pure child components will also rerender.

  • @freeversion825
    @freeversion825 ปีที่แล้ว

    How i prevent refresh?

    • @exacode
      @exacode  ปีที่แล้ว

      I didn't understand your question, could you please elaborate which refresh you are referring to?

    • @freeversion825
      @freeversion825 ปีที่แล้ว +1

      @@exacode I was saying about page refresh that happens when u up state with that function. This was my mistake that it didn't work. Ur video was rly helpful ,tnx

    • @exacode
      @exacode  ปีที่แล้ว

      @@freeversion825 When we are updating state, then React automatically re-renders the component and shows the latest state in the screen. This "re-rendering" is similar to page refresh but not exactly. Because here in re-render it does not refresh the entire page instead the specific component where the state got updated, it just re-renders that specific component.
      In this example we are updating the state in parent component. And in React when we update the state in parent component then it re-renders all of its child components. This is the default behaviour of React.
      Hope that helps! Let me know if you have any further questions or doubts.

  • @iprocoder
    @iprocoder 2 ปีที่แล้ว +3

    This doesn't seem practical. Not every component is rendered in App.js. Unless one has to create a non-rendering parent component. I will recommend avoiding this method and using Redux instead.

    • @olenayevtushok2014
      @olenayevtushok2014 2 ปีที่แล้ว

      Thank you, I'll read about Redux. But this method is pretty useful for beginners...

    • @the13nth25
      @the13nth25 10 หลายเดือนก่อน

      @iprocoder It doesnt have to be app.js though. You can lift a state to any parent component and sibling components in that component can both have access to it.

    • @exacode
      @exacode  10 หลายเดือนก่อน

      Yes correct