- Podcasts
- ReactJS Developers Podcast
- Higher-Order Components vs Custom Hooks in React – Understanding Code Reusability and Logic Sharing
Higher-Order Components vs Custom Hooks in React – Understanding Code Reusability and Logic Sharing
ReactJS Developers Podcast
- December 3, 2026
- 49 min
- Episode 10
About this episodeIn this episode, we explore two important React concepts: Higher-Order Components (HOCs) and Custom Hooks.Both techniques help developers…
- What Higher-Order Components (HOCs) are.
- Understanding how HOCs work in React.
- Creating and using Higher-Order Components.
- What Custom Hooks are.
- Creating reusable Custom Hooks.
- Understanding how Custom Hooks share stateful logic.
- Key differences between HOCs and Custom Hooks.
- Advantages and disadvantages of each approach.
- Practical use cases for both techniques.
- Common mistakes when implementing reusable logic.
- When to choose Custom Hooks over HOCs.
- Best practices for writing reusable React code.
- React.js beginners and intermediate developers.
- Frontend engineers.
- JavaScript programmers.
- Software engineering students.
- Developers interested in React architecture and clean code.
- Anyone preparing for professional React development.
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Higher-Order Components vs Custom Hooks in React – Understanding Code Reusability and Logic Sharing
Now we are going to discuss HOC and custom hooks. Both are important but custom hooks are most important. HOC is mostly used in legacy code bases. Recently you use less or less than HOC. In this case, you prefer to use custom hooks. So, we will see both. There is not much rocket science here. It is a small concept. If you learn HOC, you will also get custom hooks. Or if you learn custom hooks, you will get HOC. So, both are similar things. In custom hook, you have a little code and more clean syntax. So, we use custom hook more. Rest, learn HOC also. Who knows, in the interview, you will be asked this only. So, HOC, custom hooks, you should get both. In maximum cases, we will use custom hook. And in all projects, you will get custom hook. So, custom hook, So, what is higher order component? I will take you to the direct code because it is very simple. If you have basic idea of react, how props pass, how we manage state, then you can understand it easily. And we have already discussed this. So let's quickly come to the code and here we have already set the folder structure of react along with tailwind css. So you know all this, you can do it. Tailwind css has no such need. If you want, you can also use normal internal css, there is no problem. I am going to use tailwind here. I have set up tailwind here and you can see the folder structure along with it. So app.jsx is absolutely clean now. Here you will not see anything in the browser, we have not written anything yet. So, first of all, why should we use higher order components? So that you can understand in a single line. Use it because you can reuse complex logic and complex UI. That's it. Complex logic or complex UI. Maybe you are making a component which has a lot of complex logic. And you have to use it in multiple places. So you will go to write that complex logic everywhere. Or you have a complex UI which you have to combine with another UI. And maybe this UI can be used with some component and can't be used anywhere. So, in that case, what will you do? It needs to be reused. So, how will you write the logic separately or how will you design the UI separately so that you can reuse it? You will understand, you will understand now. Rest, you will think that you also reuse the components. What is this? So, now I will tell you. As soon as I do the code, we will learn a little while making it. You will understand immediately. So, first of all, I make a new folder here named components. and I will make two components here. The first component will be alpha.jsx and the second component will be beta.jsx. Let's do rafc in beta.jsx and rafc in alpha. So these two components are alpha and beta. Now what we have to do is, assume we have a need like this. We have multiple components now. Assume that we have made many big projects with many components. In some components, you need to take the look of a card. For example, this component alpha.jsx. All of it has a UI design. You have H1 and Paragraph. Take H1 at the top. Let's call it heading only. So, you have a component like this, you have a beta component. So, in these two components, you need to give it a card design. Means, you want the card design to come in both of them. It should look like a card. So, you will make the same UI here and the same UI here. You will do the same. Make it with Tailwind or CSS, make it with anyone. You will make the same UI here and the same UI here. So, you will get the card look. But I am saying, there is no need to do this. You make such a reusable UI, so that after wrapping, you wrap alpha, and it will be applied in alpha too. If you wrap it in beta, then it will be applied in beta too. Okay, can we do something like this? Exactly. We can do it through higher order components. Along with that, we can do it through custom hook too. Let's see how we can do it through higher order components. So I am making a file here, and I will give its name. with cardlook.jsx ok, here with will be in small letter although if you give capital then there is no issue but give in small letter this is standard naming convention higher order components in this way basically if you see in react official documentation then you will get in this way w i t h and after that as you write with ml you have to write in this way here I have given you notes so here you may not get the name, here code etc. is given, you can understand by looking at it that here W is small, after that in camel case B, B is your capital, so this is your standard naming convention that it will start with with, you will see that it will start with use, in this with prefix it will start with, so you have to put with, it is not necessary, you can give any name, just naming convention is there, if you keep a little in mind, it will be good, so with card look and here I will put a component. So this component is a normal component, there shouldn't be any issue here, there shouldn't be any issue here. I will remove this, its use is not there here. So this normal component returns an HTML, ok? HTML is returning to you. What will I say? I will say that instead of returning HTML, listen carefully to me, instead of returning HTML, return only one component here. What should I do? Listen carefully. It looks a little confusing to see here. So listen carefully, you will understand. Here I am saying that instead of returning HTML, you return a component. And how is the component? It happens like this. That means you have to return a simple function here. And what will happen inside this function? It will be HTML. That's why we are calling it a component. So in one of your components, instead of returning HTML, what did you return? You returned a component. Something like this. This component is done. and here I return, definitely, if it is component, we will not return, so UI will not be seen. So here I am returning h1, this is nested component. There was one component above, inside that we have returned a nested component. We have returned a component. Now let's come to app.jsx, I have to use alpha.jsx here. Before alpha.jsx, let's use with card look here. Why are we using it here? Because we know that it is being treated as a normal function. A component is being returned inside this function. Inside the component. Just like in the function, inside the function, we used to call it as a higher order function. Here, in the same way, inside the component, we are calling it as a higher order component. So, here, inside the component, there is a component. So, whenever we call this, with card look, and here, how does w become capital? We have written w here as small. And here also, it has become capital. However, default If it is export, then there is no issue. But I just told you about naming convention. With card look. And here also with card look. And now come to app.jsx. Once again, you import it. Okay. Here I am saying with card look. See, import is also done. And I called it in this way. So, as soon as I called it, what is returning? See carefully. A component is returning. So, what will we get here? We will get a component in return. So, let's save it in a variable. And let's give its name. My component or with card look component with card look component. And a little bit here you have to keep in mind that I have given a capital W here because this is a full component and we are going to use it here. I gave small here because it was sort of a function and we are returning a component inside it. Otherwise, if you give a capital here, there is no issue, but here you have to give capital and not small. So, with card look component and I can use it as a component. Really, can I use a component? Definitely. Why can't I use it? This component is returning. So, this component is returning. In this, you have a component. So, how do we use a component? In this way. So, now you will see here. So, this is nested component. It is so clear. I have done very little. I have not done much. Just a little. Here you have to keep in mind that there is a function outer. This is outer function and we are returning a component in it. Whenever we call it, it will return a component. So, this variable is a component of the app. So, we have called it as a component. That's it. Okay. Do you understand this much? Okay. Now I want to put alpha in withCardLook so that in return it returns a component with cardLook. That means it will be alpha's UI. Whatever is in alpha, h1, div, paragraph, everything will be there. But in that cardLook will be added. WithCardLook. You can see by the name itself. WithCardLook. Alpha withCardLook. So here first of all we will import alpha. Import alpha. Alpha component has been imported and we will send alpha here. was a function in which we sent the alpha. If we send the alpha, can we receive the alpha here? Definitely, we can receive it. You can give the name of the parameter here, I will give it here. This is also a component, that's why I have written it in capital letters. There are only a few things, just keep in mind. We generally write the component in capital letter. When there is a function, we start with a small letter. So, this was an alpha component. So, here we will receive it as a parameter. Wrapped component. And we will render this wrapped component here. Okay. Here. And how will we render the wrapped component? Obviously, like this. If it is a component, then we will render it like a component. Alright. So, here you have this wrapped component. See this. What is the benefit of this? You can render the alpha directly. Now you can use it with any card look you want. You can use it with any card look you want. You can use it with any card look you want. You can use it with any card look you want. Let's give it rounded to excel. This will be attached to the wrapped component. This will be added to the component you want to pass. Okay, you have passed alpha here, alpha has come here, alpha component is being rendered, above that this UI has been added and this whole component has been returned after being added. So here you are getting a component and you are rendering that component here. So now this alpha is with card look alpha. Okay, with card look alpha. Alpha component is there but with card look. Card look has also been added here. So now I render this card look here and you see here this card look has been added to this alpha component. The advantage is that we can use the withCardLook with any component. You need the same card in beta also. So, I will call withCardLook and pass the beta component. And we will get const withCardLook. Beta will be with card look. Or say beta with card look. Or with card look beta. Whatever you want to say. Beta with card look. This will look better. Beta with card look. Here also. Put this whole thing ahead. Sorry. Here with card look alpha is there. Alpha with card look. Like this. Alpha with card look. So this alpha came with card look. And below this beta came with card look. So, we have done this much work here, and the card look has also been added to this. Beta has also come with the card look. And if you want, you can give a margin bottom here for the time being. You can give any design here, you are just learning. So here is the margin, so this margin will be added to every card. So now whatever you add to this card, it will be added to all wherever you have wrapped it. For example, if you have wrapped the alpha, then that design is being added to the alpha. If you have wrapped the beta, then that design is being added to the beta. So whatever component you take with the card or whatever you make in the future, if you want to give a grid look or if you want to wrap it in a flex box, if you want to make something of your layout, if you want to wrap something by making your layout, then whatever component you will do, it will be applied to all of them. So this is a special thing. And not just for UI, you can use it for logic as well. For example, in card look, you would have written logic here. So that logic would have been applied to everything. If you are making an authentication system, so you want some components to work on the basis of authentication, then you can add authentication there. With authentication component. So, if you send alpha, then with authentication, alpha with authentication, if you send beta, then beta with authentication. So, there the authentication logic is also applied in alpha and beta. There is no need to apply it separately. One, you have made a higher order component. Through that high order component, whichever component you wrap in it, you will get that logic or that UI from that higher order component. Okay. Is it a good thing? Exactly. You can do a lot of things in it. The logic is that you have an outer function and a component in it. And whenever you call it, a component will be returned. And in that component, you have rendered a wrapped component. There is one more thing that I want to show you. You understood this much, right? Let's practice one more time so you will be clear. So, we are clear with card look. For now, I will remove it from here. And we will comment the code of with card look also. Now what we will do? Let's make one more here. Did I delete with card look? So, so, so sorry. I have to give this code too. So with card look, look, it's here. Okay, I'm not deleting it. With card look is here. I'll make one more. And here we give the name HOC. Higher order components with card look. Let's put it in here. Okay. And now that it's in here, we'll have to make changes here as well. Otherwise, if you take the code, you'll make a little mistake. In HOC, with card look. Okay, now it's fine. So let's comment it now. Okay. And let's make another one in HOC. Let's make it with border. Okay. With border dot JSX. So what we have to do in with border, we will simply add a border. So wherever we need border in component, we will call with border HOC and our work will be done. Okay. In the same way, you can also perform logic. Really? Yes. Really you can perform logic. So we will perform some logic in this and see. RAFC with border. Okay. And here, let's say, let's put a use effect. And what logic will we give? Authentication, etc. Right now, no logic is coming to my mind to give that logic. For logic, we will make a custom hook and see. We will work on the counter there and see. You can apply the same logic here as well. But I have thought of that example that I will tell you for the hook. So you will understand better. So, you can see the same example here. This is your self-work. You can also do the logic work here. So, for now, I will make a border and show you. So, class name, not here, I am so sorry. With border, this is your component. Now, I need a component in it and I have to work according to that. In return, I have to return a component. So, what will I do? I will return a component here in this way. Okay. Whatever component comes here, we will add some UI to that component and return a new component. With border. Okay. So, here, div, class name, and border. Okay. Border. And give border 4. Border 4. Very good. And give border black. Okay. This is also good. border applies the same CSS property as border-4. So remove this, your work will be done with border-4. And here you will have a component, wrapped component, which you have to wrap here. Whichever component you have to wrap with this border, that will be your component. So simply you can also say component here. Component will be coming and this component will be here. Not like this, call it as a component. So this component is here. Let's come to app.jsx. And now what will we do? Now whatever component we will pass here, your border will be applied to that component. Your border will be applied. And that new component with border will be returned here. Okay, let's try it. So here with border. And let's pass alpha in it. So as soon as I passed alpha, border was applied on alpha and a new component was returned. This is what we are doing here. This is an alpha component. A border has been applied on alpha and a new component has been returned. So we will save this new component in the variable. Alpha with border. Alpha with border. And here we have alpha with border. And now let's come here and see. So maybe there is some error. Alpha is not defined. Alright. So we had commented this. Now it is fine. Let's reload it. and there is no error, but we can't see anything here, why? maybe we have done something wrong in the with border, okay, here is the component, we have not returned in the component, if we do not return in the component, then we do not see anything on the UI, you know, so we have to return here, and now we can see this, this is the alpha component with border, okay, in the same way, we can take beta here, the beta component came here, and this is now beta with border. So you can also use logic here. And we will also see the logic with the help of custom hook. But with this much HOC, you can also do it on logic. Okay. And we will also see the logic one with the help of custom hook. You can do the same work here as well. But you don't have to compete with HOC so much because HOC you will use in very rare cases. You will use it only when you get it in legacy code basis. Otherwise, you will use custom hooks only. You understand its syntax better. The code also seems more readable. So, in maximum cases, in maximum projects, or if you are making the project by watching the tutorial from somewhere, then you will see custom hook only there. Ok, now let's learn custom hooks. Did you understand this much? Absolutely understood. Ok, I'll do one thing. I'll do one thing. This whole thing. Why am I commenting? By removing this comment. Remove this comment too. And remove this comment too. And remove this too. Ok. Let it be. And by copying this whole thing, I I'll put it in the notes section. Basically, by making a notes folder. And this is our HOC. Okay,. txt. And this is your HOC code. Alright, you'll get this in notes. And now we can clean it. Okay, we learned HOC. Clean this too. Very good. Now we're going to discuss Custom hook. So, custom hook also has the same work. To reuse complex logic and complex UI. And this will be very easy to see instead of HOC. So, we remove bit border, alpha, beta. We will use alpha, beta right now. And here it is all cleaned up. You can come here and read some notes if you want. A higher order component is a function that takes a component and returns a new component with enhanced or additional behavior. Keep this in mind, if you are asked that in higher order components, the component we pass as a prop, are you modifying that component or are you adding some new property or new additional behavior? So definitely you have to give the answer that we don't modify. If you look here carefully, where are our notes? Here we were passing beta in with card look, where is with card look? It was here, right? Did we delete it? HOC is this one, right? With card look, whatever component we were sending here, we were giving it as it is rendered. We were not doing any modification in it. Okay, here we are adding additional behavior or adding additional UI, adding additional logic. We are not changing anything in it. So we don't modify here. Okay, one thing is left here to tell you. I will tell you that too. How will you pass props? How will you pass the props? The important thing is missing here. So let's bring the whole thing here again. And I want to tell you how to pass the props. Like if you pass props in the alpha component, then you would be receiving props and working in alpha. Okay, suppose I want a user named props here. I want to render that here. User. Now if you come here and see. So you can see the user. I put mk in the user by default. So, can you see it? Here you can see it. But I want to send something else as a props. So, how will I do it? Here we have used the concept of higher order. Here we cannot directly send props. So, how will we send props? It is very simple. This new component which is returning to you, will you try in card look or in border? Let's try in border or in card look. Let's try in card look. So alpha with carlook, here we have to send a prop in alpha. The alpha component we have made here, we have to send a prop in this alpha. We have to send a prop in this alpha. So how will we do it here? We can't send it here. Higher order component is being used. In return, a component is being returned. And we are using this component here. So how will we send a prop? We can do it easily. There is no issue. Look carefully here. Understand a little structure. This is an outer component. Okay. Inner component is this one. And this is also your return. Okay. That means, the component you are getting in return, you are getting this component. Okay. So, take props here. Take props here. Okay, you can take props here. Definitely, you can take props here. And if you send props here, then who will it go to? It will go to this component. If you send props here, then who will it go to? It will go to this component. Okay. Send and see. So, here I send user. M-A-N-S-L-A-L. Okay. So, I have sent the props. And in alpha with card look, I want to see if you are getting props or not. You must be getting props.user. And let's see here. We were rendering the whole component and we can see props.user on it. But should we have sent it here? No, we should have sent it in alpha. We wanted it to come in alpha. So, there is no issue. We will send these props in this component. And we will spread all these props and pass them here. It is a bit complex to see, but it is very easy. Now understand this carefully. This component, wrapped component, or you can just call it a component. Okay, whatever component we are sending here, what is that component? That is alpha beta. So, this alpha beta is coming here, isn't it? Props have to be sent inside alpha beta. So, here we have passed the props. Okay, now where will these props go? Inside alpha beta? No. These props will go to us inside this component. Inside this component. This. inside the nested component. Where to send? Inside the alpha and beta. Where is alpha and beta? Inside this component. Okay. So, we sent the props here and spread them here and sent them to this component. That means, it is going to the alpha indirectly. Okay. It must be coming to the alpha. It must be coming. Here, see, in the user, mkl should be visible by default. If we send some props, then that props will replace it. Okay. If we send something in the user, then it should be replaced. So, see here, minus red is visible. Okay. What was visible earlier? If we don't send this here, So, see, mkl was visible. And after sending here, now you will get minus. So, in this way, you can also send props. So, there is only a way to write. A way to write code. A way to maintain code. Higher order components. There is no separate concept. There is no separate logic here. There is nothing of react. There is only a way to write here. Okay. So, you also understood this. Now, I will give it as a notes. So, in HOC. Okay, I have given notes to it. Copy paste again. So here this props will also come to you. Very good. You have also learned to send these props. And in app.jsx. Let's clean it. Remove this. Remove this. Remove this too. And now let's discuss. What? Custom hook. Okay. So here. A higher order component is a function that takes a component and returns a new component with enhanced behavior or additional behavior. We don't do any modification. component, HOC, enhanced component. Whatever is HOC, you pass a component in it. In return, it gives you an enhanced component. This is what we were doing. We were passing alpha. In return, we were getting an enhanced component with border or with anything. Whatever you have. It follows the same idea as higher order function. The higher order function that used to work in JavaScript, here it is doing higher order components. Higher order function is read in JavaScript. It is very good there. All the things we have done. Prox 52 to 53 hours video. One shot is also available on YouTube. You can see. So here you can understand the basic syntax of HOC. I just told you. You can see it is given in notes. What is custom hook? Now let's discuss this. Custom hook is a JavaScript function. This is also a normal function. If you talk about hook, then what is a hook? It is a normal function. Where you have to do something. We are getting things made. So, what happens in custom hook? JavaScript function is there which we make ourselves. Okay. In React, that starts with the word use. You will get use in it. Whether it is custom hook or React's made hook, you will get use in it. Okay. That's why you make custom hook yourself. So, give use in it so that we know that we are making hook. So, like in higher components, you were getting with. In custom hook, you will get use. Use, counter, use something, use something, etc, etc. uses other hooks inside it, inside it, okay, in custom hook, we can use other made hooks, by utilizing that, we can make our custom hook, and we will make that now, allow you to reuse logic, across components, obviously, logic can be reused, UI can be reused, if you want, in the same way, as we were doing there, But it generally says that you should only use logic and not UI. But we can also use UI, we don't need higher order components. Custom hooks do not return JSX, they return data or functions. It depends on what extension you are giving. If you are giving JS, that means you are returning data. If you are giving JSX, that means you are returning UI. It completely depends on you and I will tell you that now. You can depend on yourself whether you want to return data or UI. They help extract reusable logic, not UI. Okay? He is saying this, but we will not agree. We will try. That's all. Let's see how to make a custom hook. So, let's come to app.jsx. If you want to make a counter functionality, let's say you are making a counter application, or you are using the functionality of counter in multiple places. Like if you are going to add to cart, then you are using plus minus etc etc. Then maybe somewhere else, add to cart or in product etc. somewhere else you are using plus minus logic, increment, decrement. So there also you are needing. In your application, you may be using the functionality of counter in multiple places. So you have to write logic everywhere. Which logic? This. count comma set count is equal to useState. You will write this. And this is just useState, a normal hook. You will write this. But along with that, you will also make the increment functionality. You will make an increment function. You will make a decrement function. If you need to make setByValue, you will make that. You will write multiple logics here. And you will write all of them again and again wherever you need. So I am saying that if you are getting a need again and again, then make a custom hook. Where you will get the increments, decrements, set values. You can do everything there. How will you make it? Let's see now. Custom hook. Here I will give the name of the new folder. Custom hook. And nothing else, just a custom hook. We have a folder. We will make a hook in it. Give the name. Use counter. If you are giving. js, that means you want to work with data only. And if you are giving. jsx, that means you want to work with UI also. Use, border, use, card, look, what we were doing now, you can do the same work here also. Right now, we want to work on data, so we will give. js name. So use counter.js, alright. What will happen? A normal function. Here, the nested one is also not there. A normal function. So, const useCounter is equal to this function. And if you want, you can export it here also. We will use it in multiple places. Now, in this function, can you hook call? Yes, you can. Definitely, you can. So, can you do it here? Absolutely. Many people get confused that we are writing JSX, that's why we can hook call. It's not like that. In a function, you have permission to only hook call in react. Now that function means basically. js you are using file or. jsx. In function, you can hook call. But before return, before body. So here you can hook call definitely. Use state hook call exactly. Whatever hook you can call here. So we did hook call. We have to make counter functionality. So for this, const count comma set count is equal to use state See, count and set count came from use state. Okay. We want to reuse the main logic here. So we will write that logic here. First of all, the logic of increment. Now the logic I am writing, these are small, small logics. You will write very big logics in the project. So for that you have to make a hook. It is not that I am telling these small things, then you have to drag it. You will get big logics and wherever you feel that this logic is being reused in multiple places. So extract that logic at one place as a custom hook. Okay. So const increment and this is our function. What to do here? Set count. Count plus one. Count plus one. Okay. Then we will make a function const decrement and this will also be a function where set count will be done. Count minus 1. Okay. After that, we will make another function here. const setByValue and here we will take value and set that value in count. Okay. This value, whatever we pass, that value will be set here. So, here we have made three functions and along with that, we will use this count value. Now, set count is not needed. We will just show count where we have to render count. We have to increment the increment function. Decrement for decrement function. SetByValue for setByValue function. and we will return this in this function. Count, we are returning an object, look carefully. We are returning in object format, because we have to return multiple things. So, in key value pair, you can return in object format. So, I will return count, and I will return increment. Value and key are the same here, so I am just writing count. Otherwise, count, colon, something, you can write. You know that, it is a normal JavaScript thing. So, count, increment, along with decrement, and setByValue. So, your custom hook is ready, useCounter. So, wherever you will use useCounter, there you will get four things, count, increment, decrement, setByValue. Wow! Now, come here and see, as you normally call useState like this, useState you don't have to use now, you have made your own custom hook, useCounter. UseCounter you will use here. Yes, remove useState. We made our own hook. useCounter and in useCounter useCounter here you have to take initialState so that initialState will come we will put that initialState here first it was 0 but the state we will pass should go there in initialState we passed 0 so here 0 will be set so in return what will it give us let's see what it is giving so let's destructure it object is returning see here object is returning so here We could have saved it in the variable and accessed it from the dot notation. But we will destructure it. We are getting the count here. Along with that, we are getting the increment. We are getting the decrement. We are getting the set by value. We are getting everything. You just have to use it. Okay? You just have to use it. So here, I will show you the count in H1. In the H1 tag. It will look a little big. It will look good. Right? And here we will make a button. and increment button in the same way you will get a decrement button and then you will get a set value button set value where will the value come from? so for the value you will have to make an input box here and let the type text remain let it be in the placeholder enter value Alright, and now we have to make a state for the changes we will make in the input box. So let's make it here. const inputValue, inputValue, set inputValue is equal to useState. Oh man, useState, okay. And this will be empty by default. So set inputValue here we have to do. We have to put onChange in the input. You know all this. Set input value to E.target.value. Where will E come from? You will get the value from E.target.value. So whatever you type here, it will come in the input value. And if you want to make a controlled component, you can also pass the input value in the value. So this is your input. Now your input field is ready. Now see how easy it is to implement the counter functionality. We just used the useCounter hook. We had to show the count, we have shown the count here. Where did the count go? Here it is. You can see the count here. We have to increment when we click on increment. So what do we have to do now? Nothing. There is logic written here. Just put onclick here. Increment. Put the reference. Done. Really? Wow! Logic is already written. So, we have to use it here. On click. Decrement. And where is all this coming from? Increment, decrement. From use counter. See, decrement is also happening. And the value we are writing in input, that value is being saved in this state. In input value. So, from here, we will pass this value. On click. Now, we have to call in this way. Because one We have to pass the argument as well. So setByValue was the function. We had made setByValue function. Here we are getting setByValue. In this setByValue, we will pass the input value. Okay. So whatever we are writing here, 56, setValue, see here 56 came. Here I will write 86, setValue, 86 came. And if we do increment, see increment is going wrong now because we are putting a string here. So, it is going in string format and you know in string it gets concatenate instead of increment or decrement it gets concatenate. So, here you have to pass number. You can do one thing, if you make number here, then number will go. Number. Okay. Number. Okay. So, now you will have this in number format. Reload it once. Okay. So, let's increment. It is 4. Here, let's put 10 and set the value. So, it is 10 and now we will decrement. So, it is playing with number. Then it is working. So, it becomes so easy that you have separated a logic. Now, you have to use it anywhere. You will just call use counter hook here. You will get count, increment, decrement set by value. You will get a lot of things. You just have to use it. Now, in the same way, in the same way, as you have done the logic work here, you can do the UI work in the same way. Let me do it. Let me do it once. use use card look dot We have to make jsx because we have to return a UI here. function const export also export const use card look here it will take a component right it will take a component in that component basically some ui etc. will have to wrap ok and here we will return a component and return here otherwise it will not be visible on the UI so component as we were doing normally in the higher order component so this component is done see it is visible so this is your normal custom hook here we are returning the component And in that component, we will render this component. And because its name is use card look, so definitely this card look will provide. So here in class name, we make a simple card. 500 or 600, 700, whatever you want to give. We will give padding of 10. And what else do we have to give in the card? Let's make it a little rounded. Rounded to Excel. Okay. So this is done. And similarly, you can receive props here. Props and this props can be passed in this component. Dot dot dot props. So that whatever component you are wrapping, if you want props in that component, you can pass it too. Okay. So this is your complete use card look. And you can come here and use it. Really? Exactly. Exactly. Okay. Let's use alpha here. Use card look. And here I will import our alpha component. Import alpha. From dot slash component slash alpha. Okay. So, we have added that alpha component. So, in this alpha component, card look will be added. And in return, it will return us an enhanced component with card look. So, const alpha with card look. Alright. Now, you can use this alpha with card look as a component here. And if you want, you can also pass props here. Exactly. In alpha, you were taking users here. Where did it go? In app.jsx, you were taking users in alpha. So, you can also pass users here. You must be getting suggestions too. User. No, you are not getting it. No problem. First, let's see if it is working or not. This is working. Card look is working. Alpha is just this small. Rest, card look has come because of this. Use card look. Because of your hook. So, we can pass the user here as well. That's a different thing. We are not getting suggestions like the higher-order component. So, I give the user here minus your lol. So, let's see that it doesn't come here. It came. Okay. And now, if your observation is good, then look carefully. The one I am calling custom hook here, it has actually changed to your higher-order components. As we were working here in higher-order components, I will show you the code of higher-order components here with card look. Look at this. The code here and here, there is not much difference here. useCardLook.jsx, withCardLook.jsx and this useCardLook.jsx. Here we have basically exported default, RAFC because we have used it. Here you can do it like this. Okay. You can do named export. So, there is no difference between this code and this code. There is only difference of name. Here with is used and here use is used. So the way we are making custom hooks, in the same way we can also make hooks for UI. And we can also call it a higher order component. See, there is not much difference. Higher order components and custom hooks. Both are nothing different. It's just a way of writing. The difference between both is that your higher order component is focusing more on UI. And at the same time, you can also mix logic there and write. In this way, it was designed. What was designed? It is our responsibility. UseCounter focuses on keeping the logic separate. UseCounter focuses on keeping the logic separate. I have mentioned this in the notes as well. Both are the same concept. Talking about hooks, we do not focus on JSX. They return data and functions. They help extract reusable logic, not UI. We don't focus on UI here. We are trying to separate logic. You can work with UI too. There is no issue. But it will be your higher order components. There is another way to use templates. I have already mentioned templates. We call them templates. You can make templates and work. That method is also good. That way we have done in some projects. And we will do in future projects also. So do it this way. Basically you have to make the code readable. Rest is your wish. What do you want to do? Custom hook is used more. We like to keep logic separate. We like to keep UI separate. So hook and UI work together. Rest you want to make reusable UI in the same way. Then you can use templates. Instead of higher order component. And if you want to do higher order component. Then instead of with. Use it. Use card look. So it will be treated like a hook. It's just naming convention. And there is a way to write a little bit. There was nothing else in it. The same concepts are repeating. The way of writing has changed. Okay. So if you understood this much. And if there is confusion. So, try it once by yourself. Basically, try it by keeping logic separate. And try the UI portion once where we discussed higher-order components. You will understand that there is not much difference between the two. If you are writing logic, then your single function will work in this way. And if you are making UI, then you will need nested components. Because you have to pass props as well. If you are working by making templates, then you can directly send props to it. And you can pass your UI directly as a children. So we have seen that way in the project as well. And we will see further. So this concept is also clear to you. Let's go to the roadmap once. Our roadmap xmind. Here is our roadmap available. Let's see once that what things have been completed. So I log in quickly. And let's see one last time that what is left and what is completed. So for now, We have almost completed everything. This first phase is of JavaScript, we have completed this. This is basically complete. Here we have done everything like event handling, reference, use reference. We have also done the use effect. We will talk about the life cycle once. Conditional rendering, list rendering, higher order components, which I had left, I had to tell you together. along with custom hook, so that is also done. Higher order components. Did I write custom hook somewhere here? I didn't write it either. Here in common hook, you also had to get a custom hook here. Okay, here I am. In common hook or separately, you can do it. This will not come in the common hook, your custom hook. Here you can work by removing the branches separately in between. So you understand custom hook, that you can also make custom hooks in hooks. So this is done. Then after that phase 3 which was already done. In phase 4 we have done fetch axios. React query is left. Routing portion is also done. In hooks we have done use state, use effect, use reference. Use location, callback, memo etc. we have to do now. So 2-3 lectures here. And in state management we have done everything. We have context API, reducer is left. Context API plus reducer. We will do that through project. Reducer is not to be explained separately. We will do it through project. Context API plus reducer. So context API is done, just end is done, redux, redux toolkit is done. In styling, we have CSS tailwind, CSS daisy UI, styled component, material UI, and sad cn etc. So we have explored so many libraries, rest of them are of the same type. So we will go through projects. However, you can say on sad cn that a separate video can be brought. So I will try a separate video on sad cn. There are many other libraries. It's the same way to explore everyone. The way we did it in Material UI, the same way everyone else has to do it. Then after that, you can do all this for animations. And then some advanced topics, projects etc. And some advanced topics in which maybe you want to go. If you have become a good developer, then you want to go ahead in advanced topics. Or you want to move towards the backend, it's your choice. So I will also see how we work. So, for now, that's it. Almost everything is completed. There are some last topics. If you want, you can move on in the backend as well. And then, you can learn all the videos that will come here. There is nothing complicated left. You can learn with projects as well. So, that's it for now. See you in the next lecture. Till then, keep exploring and bye-bye.
