React Class - 2

 todo - https://towardsdatascience.com/build-a-simple-todo-app-using-react-a492adc9c8a4

Curd - https://www.freecodecamp.org/news/how-to-perform-crud-operations-using-react/

https://github.com/nishant-666/React-CRUD-Operation-V2

 https://mockapi.io/ 

E:\Projects\ReactJS\react_curd_mockapi.io

So, we start with the main function of the App. We will define a todos javascript list which would contain all our todos and also carries the status of each todo whether they are done or not. We will use setTodos and will use React.useState which is enabled by React Hooks.

function App() {
const [todos, setTodos] = React.useState([
{
text: "This is a sampe todo",
isDone: false
}
]);
}



In the above example, useState is the Hook which needs to call inside a function component to add some local state to it. The useState returns a pair where the first element is the current state value/initial value, and the second one is a function which allows us to update it. After that, we will call this function from an event handler or somewhere else. The useState is similar to this.setState in class. The equivalent code without Hooks looks like as below.







Comments

Popular Posts