![]() ![]() ![]() Let’s take a look at how the Context API can be used without the help of hooks. Let’s delete the App.js file as we don’t need it anymore and write our code in the index.js file directly. I used to shudder at the thought of render props and higher order components in my initial coding days.Ĭlearly, someone else some similar thoughts, and so they created Hooks to make life and code simpler for all React Developers!īut let’s get back to useContext hook and see how we can use it. For example, you might or might now want to make calls to an API, so why use something that adds extra code to your app that you are not using?Ĭlasses also bring a whole lot of confusion when you want them to communicate with each other. The lifecycle methods are known for containing a lot of code that you may or may not want to use in your app. They can only take in props and return some HTML (JSX). But it also provides us access to something called lifecycle methods such as componentDidMount, componentDidUpdate, and more.įunctional components are pure functions, like the ones we write in vanilla JavaScript, and they do not have access to any state or lifecycle methods. Like I said before, Class components are used in React when you want to use state in the component. You use write Classes when you want your component to have some state, and you use the Functional components when you think your component won’t require any state. There was a clear separation between Stateful and Stateless Components. ![]() If you ask me, things were pretty good the way they were before Hooks were introduced. ![]()
0 Comments
Leave a Reply. |