React Higher Order Components Tutorial

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

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

  • @cyrusbesabella5938
    @cyrusbesabella5938 4 года назад +3

    yes this one is hard, but if you don't know JS higher order function itself, surely you wont get this in one sitting. Thanks again sir!

    • @Techsithtube
      @Techsithtube  4 года назад +1

      Yes , that is true. you need to know the concept of higher order function.

  • @Sapphiamur
    @Sapphiamur 4 года назад +7

    This is kind of hard to digest for someone like me who's just starting with React/JS in general, but a great example nonetheless. I'm gonna go over it multiple times and see if I can replicate something similar in my code :d. Thank you!

  • @swaroopvoleti
    @swaroopvoleti 5 лет назад +5

    Great stuff, you made me use HOC comfortably without any issues and I have to develop similarly in my project which is creating multiple iterations of buttons.

  • @2802ize
    @2802ize 5 лет назад +5

    can @techsith or anyone explain @13:10
    Why do we have to return the wrappedComponent from inside of return function wrappedRender(args){...} ,
    and not directly...?

    • @HAIM3307
      @HAIM3307 5 лет назад

      My thoughts exactly!

    • @its4zahoor
      @its4zahoor 5 лет назад

      I hope you understand now 😊. HOC return a function/component.

    • @ytb.addict
      @ytb.addict 5 лет назад

      Just a Chutiya explaination he gave

    • @indowestlife
      @indowestlife 4 года назад

      Now this function wrapped render would actually receive the props that button one was supposed to get and then translate those props and then the wrapoed component would be returned

  • @jeffwei8629
    @jeffwei8629 4 года назад

    I've been thinking about the HOC part of this and I like to share with everyone what I came up with. Let me know if you disagree.
    The goal is we want to take the original component and get an updated component, by passing the original component into a function. So I changed the functions names to better reflect that.
    export default (originalComponent) => {
    return function updatedComponent(args) {
    return originalComponent(translateProps(args));
    }
    }
    In techsith's example ButtonOne is the originalComponent, I think that component gets saved in the closure belonging to the updatedComponent function. The updatedComponent function gets returned to stylesWrapper, and stylesWrapper completes it by passing in the props object as the args argument.

  • @rohandevaki4349
    @rohandevaki4349 4 года назад +1

    how are you getting the props as args in return function wrappedRender(args) ?

  • @nooruddinraotiwala490
    @nooruddinraotiwala490 3 года назад

    Where is the style wrapper class declared ?

  • @kandysman86
    @kandysman86 5 лет назад

    Why the object inside object with the styles? Ibe bever needed to use default like that, should I?

  • @ckvinothkumar
    @ckvinothkumar 5 лет назад

    @techsith - How the wrapperRender method get called? wrapperRender is built-in method in react like render method ?

  • @bahusworld5408
    @bahusworld5408 4 года назад

    How to pass two styles for the styles object and to newprops, means I want to give both background color as one style and for text color i want to use as text style separately..at that time how can i pass

  • @hiteshparashar
    @hiteshparashar 6 лет назад +1

    Hi Thanks, just one question. How the props of ButtonOne are getting assigned to parameter named args of wrappedRender function?

    • @Techsithtube
      @Techsithtube  6 лет назад

      I am passing args which is nothing but props.

    • @luizelias6155
      @luizelias6155 5 лет назад +2

      I'm having some trouble on understanding this

    • @panakure1084
      @panakure1084 4 года назад

      @@Techsithtube HOW DOES THE PROPS GOING IN ARGS, HOW DO THEY GET THERE ? DON'T YOU SEE A LOT OF ASKERS DONT UNDERSTAND THIS MOST IMPORTANT PART!

  • @soneshengg
    @soneshengg 6 лет назад

    For let _styles , do we really need a spread operator ? Can it not just be _styles = styles.default and _styles= styles.disable ?

  • @kulkarniaishwarya2527
    @kulkarniaishwarya2527 5 лет назад +1

    Hello sir, I m stuck how to reuse hoc in class components. Please anyone explain

    • @Techsithtube
      @Techsithtube  5 лет назад +1

      this is a good exmple of hoc
      function withSubscription(WrappedComponent, selectData) {
      // ...and returns another component...
      return class extends React.Component {
      constructor(props) {
      super(props);
      this.handleChange = this.handleChange.bind(this);
      this.state = {
      data: selectData(DataSource, props)
      };
      }
      componentDidMount() {
      // ... that takes care of the subscription...
      DataSource.addChangeListener(this.handleChange);
      }
      componentWillUnmount() {
      DataSource.removeChangeListener(this.handleChange);
      }
      handleChange() {
      this.setState({
      data: selectData(DataSource, this.props)
      });
      }
      render() {
      // ... and renders the wrapped component with the fresh data!
      // Notice that we pass through any additional props
      return ;
      }
      };
      }

  • @patcoston
    @patcoston 5 лет назад

    6:38 const _styles magically changes to let _styles. There are tutorials that are error free. Maybe you should record in short bursts, making a copy before each clip, so if you make a mistake, you can reset the code and do that clip again. I'm often just listening and typing, so if something magically changes, I'll miss it.

  • @Rj3rj20
    @Rj3rj20 6 лет назад

    Hello Sir, At 3:14 you switch to App.js then there is no "import React from in the ButtonOne.js" war written ... But when the code compiles successfully then i see that on 3:39 this is the first line.. It may be due to cutting of the video but I was in trouble for 15 min due to this

    • @Techsithtube
      @Techsithtube  6 лет назад

      Oh sorry, Rajat. you can download the final solution from my git site. It's In the description of the video.

  • @Middollo
    @Middollo 5 лет назад +37

    Sorry but this is not a very good HOC explanation.

  • @rajatkushwaha2965
    @rajatkushwaha2965 4 года назад

    why his audio and video is not matching

  • @bilalafzal2741
    @bilalafzal2741 5 лет назад

    passing class component in HOC gives warning
    Warning: wrappedRender(...): When calling super() in `wrappedRender`, make sure to pass up the same props that your component's constructor was passed.
    any idea to resolve this ?

    • @Techsithtube
      @Techsithtube  5 лет назад

      Its a right warning that when you need to pass the same parameters when calling super. because its calling the parent class.

  • @michaelerwin8744
    @michaelerwin8744 5 лет назад +17

    I prefer if you to go back to zen mode of teaching enlightenment rather than confusion.

  • @doaashafik3073
    @doaashafik3073 6 лет назад

    The HOC is same as the container in redux that contains behavior for other components?

  • @alanjb5791
    @alanjb5791 6 лет назад

    Is using an underscore like '_styles' an optional notation for a closure?

  • @NandhuKishorReddy
    @NandhuKishorReddy 5 лет назад

    How I can do infinite scroll react js please help me

  • @pradhumnsharma4253
    @pradhumnsharma4253 4 года назад

    Hi,
    Can I make api calls in class returned by higher order component?

    • @cnsnmms3708
      @cnsnmms3708 4 года назад

      Pradhumn Sharma you can do anything before returning the lower order component. Also you can pass the data to the loc (lower order comp)

  • @akhileshpips
    @akhileshpips 4 года назад

    what do u mean by translate one prop to other?

    • @Techsithtube
      @Techsithtube  4 года назад

      means inside the HOC you can something to change the props. so you can use same component to transform into different components. In the video , I am adding styles to the props.

  • @sandeep56944
    @sandeep56944 6 лет назад +2

    Thank you so for this tutorial, learned a lot from this. You are videos are so descriptive and easily understandable. My request is, can you do a few videos on testing react apps?

  • @rakibhossain825
    @rakibhossain825 5 лет назад +1

    Anyone please explain me this part =>
    export default (WrappedComponent)=>{
    return function wrappedRender(args){
    return WrappedComponent(translateProp(args));
    }
    }

    • @Techsithtube
      @Techsithtube  5 лет назад +1

      In nutshell take arguments of the passed components do something with it and pass it back to the same component and return .

  • @panakure1084
    @panakure1084 4 года назад

    does where args comes from?

    • @ReactWithMasoud
      @ReactWithMasoud 4 года назад

      They are incoming props that are defined when calling the component in app.js

  • @pradipspeaks9395
    @pradipspeaks9395 3 года назад

    Nice. HOC seems best when I am refactoring existing components to add some masala over it. No changes inside all existing components, just wrap it in HOC and use it instead.

  • @SonamKumari-vo2cn
    @SonamKumari-vo2cn 3 года назад +1

    Nice example for HOC

  • @TheFajaman
    @TheFajaman 6 лет назад

    Great stuff sir, your videos made me understand React much better than before, I hope you'll make something about Redux and proper way to dispatch actions from children components.
    Keep up the good work!

  • @amitk0277
    @amitk0277 6 лет назад

    Hi sir .....I like your tutorials.
    ONE DOUBT :
    How are we able to access the props of WrappedComponent in the wrappedRender(args) function .... ??? Please do reply .. THANKS

    • @Techsithtube
      @Techsithtube  6 лет назад

      Becase i am returning a function where the props are automatically available.

    • @panakure1084
      @panakure1084 4 года назад

      @@Techsithtube not clear. this is the most important part of HOC paradigm and you just skipped it. for fuc sake! made me angry

  • @debmozumder
    @debmozumder 6 лет назад

    You are Awesome sir! HOC or render props?

  • @ganeshshetty8441
    @ganeshshetty8441 3 года назад

    Best explanation on HOC ever

  • @SunilKumar-fh6jk
    @SunilKumar-fh6jk 6 лет назад

    Hey man I in a really tough situation. Please make a tutorial on how to do authentication with react. Please.

  • @dohyun0047
    @dohyun0047 5 лет назад +1

    this one was hard ㅜㅜ but thanks i see what your trying to explain i will just have get used to this

  • @calebolojo5246
    @calebolojo5246 5 лет назад +1

    I always Like your videos before it starts!
    Your simplistic style of teaching is great! Thanks!

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

    const style = {
    default: {
    backgroundColor: 'green',
    color: 'yellow',
    padding: '10px',
    },
    disable: {
    backgroundColor: 'yellow',
    color: 'red'
    }
    }
    const Child = ({ props }) => {
    return (
    IM BUTTON
    )
    }
    const HOC = ({ Component, ...props }) => {
    let _style = { ...style.default };
    if (props.disable) {
    _style = { ..._style, ...style.disable }
    }
    let newProps = { ...props, style: _style };
    return
    }
    const App = () => {
    return (

    );
    }
    export default App;
    works the same way

  • @ytb.addict
    @ytb.addict 5 лет назад

    Bahaut hi ganda explaination
    Lon'j'er Video Playlist

  • @sriramph8421
    @sriramph8421 6 лет назад +6

    Can you please start redux tutorials

    • @ruchirai5775
      @ruchirai5775 5 лет назад +1

      He has uploaded the videos on redux
      .It is pretty good.

  • @Colstonewall
    @Colstonewall 6 лет назад +3

    Clear as Mud.

    • @Techsithtube
      @Techsithtube  6 лет назад

      Lol.

    • @Colstonewall
      @Colstonewall 6 лет назад +1

      @@Techsithtube Sorry, I was having a bad night when I made that comment. Love your ch and your teaching(s)!

  • @robindergill
    @robindergill 6 лет назад +1

    great tutorial man. keep it up

  • @sakcee
    @sakcee 5 лет назад

    Thank You @techsith !!!! you should add your email or website (maybe a gastby video?) so that people can contact you

    • @Techsithtube
      @Techsithtube  5 лет назад

      My email and site is in the description of the channel. feel free to email me.

  • @pragmatic-pr
    @pragmatic-pr 4 года назад

    Tutorial is good, but, should show output with new changes

  • @patcoston
    @patcoston 5 лет назад +26

    Usually your tutorials are very informative but this one was a hot mess with too many mistakes. You wrote complicated code without explaining how and why it works.

    • @bh3326
      @bh3326 5 лет назад +2

      it's free dude. Create your own and move on

    • @eroncardoso7670
      @eroncardoso7670 5 лет назад +3

      @@bh3326 this doesn't mean feedbacks are unwelcome.

    • @kripashankarjha3502
      @kripashankarjha3502 5 лет назад +2

      tech shit

  • @0the0ambient0
    @0the0ambient0 5 лет назад

    Very helpful. Thank you!

  • @Albertmars32
    @Albertmars32 6 лет назад

    bro pleeeasee make a playlist about react with firebase cloud functions, that way theres at least one channel in the whole youtube about making a serverless web app. react, cloud functions, and stripe :)

    • @Techsithtube
      @Techsithtube  6 лет назад +1

      ok bro, I will try to make those videos. thanks for watching!

    • @Albertmars32
      @Albertmars32 6 лет назад

      techsith appreciate it brother!

  • @Jonathan-od5xc
    @Jonathan-od5xc 5 лет назад

    What are props?

  • @shakeebarsalan7030
    @shakeebarsalan7030 3 года назад

    You made it very hard.

    • @Techsithtube
      @Techsithtube  3 года назад

      I feel like, I need to re create another video on this.

    • @shakeebarsalan7030
      @shakeebarsalan7030 3 года назад

      @@Techsithtube waiting for...

  • @Cowglow
    @Cowglow 5 лет назад +1

    My man, open up your DM on twitter

  • @RahulKumar-hw7kb
    @RahulKumar-hw7kb 5 лет назад +1

    This episode was a bit confusing.

  • @vivuuc4209
    @vivuuc4209 4 года назад

    lerning, lerning, lerning

  • @MotivationFacts552
    @MotivationFacts552 6 лет назад

    Dude your are great teacher are you have Udemy course

    • @Techsithtube
      @Techsithtube  6 лет назад +2

      I dont have a udemy course however i am planning to make one soon.

  • @anilshivamurthy9501
    @anilshivamurthy9501 4 года назад

    Your all other explanations were much understandable.. This one is a mess.. Can u come up with more easier one for HOC..?

  • @moswilam91
    @moswilam91 5 лет назад +4

    I like your tuts, but this one is a bit annoying, you jumped many times and the code just disappears and you continue talking as if we were with you off camera, I would suggest you reduce cuts and try to maintain coding on camera, its more natural this way in my opinion, thanks for sharing and best Regards :)

    • @Techsithtube
      @Techsithtube  5 лет назад +1

      Yes, that video I had bit difficulty editing. I have fixed that in the subsequent videos.

    • @moswilam91
      @moswilam91 5 лет назад

      @@Techsithtube thank you for your response, one more question. do you still do js mock interviews? and if you do, is it free ? and if not how much does it cost in USD. thanks and I am a big fan regardless. cheers from Egypt btw ;)

    • @Techsithtube
      @Techsithtube  5 лет назад

      @@@moswilam91 Yes i still do mock interview. there is no cost. feel free to email me at techlover2000@gmail.com and we can set itup.

  • @Adilkhan-lm6ic
    @Adilkhan-lm6ic 6 лет назад

    Sir create tutorial series to create jquery like laibrary please !!!!!!!!

    • @Techsithtube
      @Techsithtube  6 лет назад

      you mean with raw javaScript create my own jquery?

    • @Adilkhan-lm6ic
      @Adilkhan-lm6ic 6 лет назад

      O yess yess yes plz sir. I always want to get in deep part of javaScript ..

    • @warchild2726
      @warchild2726 6 лет назад

      It is not too hard tho, just keep your head around what you wanna acomplish with your function, create that function and use it in your project after :D

  • @allistaircatto8057
    @allistaircatto8057 5 лет назад +1

    Love your video

  • @antuancaraballo9691
    @antuancaraballo9691 6 лет назад

    Thank you ! very helpful

  • @rohandevaki4349
    @rohandevaki4349 4 года назад

    it is very hard to understand, i have doubts regarding this, it is complex, you didnt explain it properly.

  • @ГеоргийРукомин
    @ГеоргийРукомин 5 лет назад +1

    Thank you.

  • @ruchirai5775
    @ruchirai5775 5 лет назад

    Genuine feedback:) example looks tooooo complicated

    • @Techsithtube
      @Techsithtube  5 лет назад

      yes, it's hard to simplify this example :)

  • @sayedabdulkarim7086
    @sayedabdulkarim7086 6 лет назад +3

    instead of using spread operator ,we can use this =>
    I am button One

    • @ColtsFan288
      @ColtsFan288 6 лет назад +3

      The spread operator allows you to merge two objects instead of just choosing either disabled or default

    • @sayedabdulkarim7086
      @sayedabdulkarim7086 5 лет назад

      @@ColtsFan288 xcatly brother, but if want to insert two different styles den we can use this also

    • @miguelrico4338
      @miguelrico4338 5 лет назад

      @@sayedabdulkarim7086 what if you have 3 or more styles you need to pick from?

  • @ManOnHorizon
    @ManOnHorizon 6 лет назад

    Thank you!

  • @navyaenneti877
    @navyaenneti877 4 года назад

    nice

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

    Just so you know,
    ./../
    and
    ../
    do the same thing

  • @paulmcloughlin5633
    @paulmcloughlin5633 6 лет назад +2

    Great tutorial.

    • @Techsithtube
      @Techsithtube  6 лет назад

      Thanks for watching!

    • @DS-rv2fc
      @DS-rv2fc 6 лет назад

      amazing tutorial thanks. it would be good if you put your code on codesandbox so we could fork it and play with it. also, it would save you the hassle of creating a react app yourself.

    • @Techsithtube
      @Techsithtube  6 лет назад

      the code is on git hub so you could fork it. github.com/techsithgit/react-higher-order-components.git

  • @krantibrid6110
    @krantibrid6110 3 года назад

    Difficult to understand with this example

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

    Not an up to mark video for HOC

  • @subhasishnathdev
    @subhasishnathdev 3 года назад

    You should've ended the video by displaying how to add other types of buttons.

  • @paulperez9599
    @paulperez9599 5 лет назад +1

    Disable means to turn off. What you have done is override your styles. You even call your hoc style wrapper. It does not make any sense to call your property “disable”. I am rejecting your code until you fix your variable names. LOL

  • @cnsnmms3708
    @cnsnmms3708 4 года назад

    You have used ‘this’ inside of an arrow func. What a shame...

  • @Travelmoments
    @Travelmoments 4 года назад

    big example..not understandable clearly..

  • @ahanamallik9409
    @ahanamallik9409 3 года назад

    hi,
    better try to make simple videos. so that beginners can understand. This is not a place to show how much you know. we are here not to see your knowledge, rather we are here to learn. so try to explain with simple example. thank you

  • @balaweblog
    @balaweblog 4 года назад

    Bad explanation for HOC

  • @pannihto7588
    @pannihto7588 4 года назад

    Typical indian code right there

  • @patcoston
    @patcoston 5 лет назад

    you frequently forget your semicolons