| by Gagandeep Singh | No comments

Understanding ReactJS Hooks

React Hooks have been added to React library from version 16.8 and they provide the functionality to use state and few other features inside the functional component without creating React class. 


The first hook is useState. This let us define a state inside a functional component. useState() returns the current state and a function inside which we can update the state.

In the example above, we used the useState hook to create a state variable called “name” and the “updateName” function to update the value of “name” state.

useState() takes a value which is the default value for the state. In our example, we are setting the default value of “name” as “pixxstudios”.  To try the code, click the link below.