
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-use-todo
Advanced tools
A lightweight todo app hook for React, Next.js, and Gatsby.
It helps you to build todo app with different skins without worring about the logic part. It has many utility methods available on the hook.
npm install react-use-todo # yarn add react-use-todo
TodoProviderYou will need to wrap your application with the TodoProvider component so that the useTodo hook can access the todo state.
Todos are persisted across visits using localStorage, unless you specify your own storage adapter.
import React from "react";
import ReactDOM from "react-dom";
import { TodoProvider } from "react-use-todo";
ReactDOM.render(
<TodoProvider>{/* render app/todo here */}</TodoProvider>,
document.getElementById("root")
);
| Prop | Required | Description |
|---|---|---|
id | No | id for your todos to enable automatic todos retrieval via window.localStorage. If you pass a id then you can use multiple instances of TodoProvider. |
defaultTodos | No | set initial state with defaultTodos . |
storage | No | Must return [getter, setter]. |
useTodoThe useTodo hook exposes all the getter/setters for your todo state.
loading: booleanThe loading variable gives you loading state. Useful for async task.
import { useTodo } from "react-use-todo";
const { loading } = useTodo();
if (loading) // do something
else // something
toggleLoading(loading: boolean)The toggleLoading method will help you set the loading state. Useful for async task.
import { useTodo } from "react-use-todo";
const { toggleLoading, loading } = useTodo();
useEffect(() => {
toggleLoading(true);
fetch(url).then(data => toggleLoading(false);)
}, [])
if (loading) // Show loading state
else // Show data
todos: Array<Object>The todos contains the list of todos.
import { useTodo } from "react-use-todo";
const { todos } = useTodo();
<ul>
{todos.map(todo => <li key={todo.id}>{todos.text}</li>)}
</ul>
filterdTodos: ObjectThe filterdTodos filtered array based on the selected filter.
import { useTodo } from "react-use-todo";
const { filterdTodos: { todos } } = useTodo();
<ul>
{todos.map(todo => <li key={todo.id}>{todos.text}</li>)}
</ul>
filtereTodos(by: string)The filtereTodos method to filter todos based on selected filter. Available value (ALL, COMPLETED, UNCOMPLETED)
import { useTodo } from "react-use-todo";
const {
filtereTodos,
filterdTodos: { filterdBy },
} = useTodo();
<div>
<button
style={{ backgroundColor: filterdBy === "all" && "red" }}
onClick={(_) => filtereTodos("ALL")}
>
All
</button>
<button
style={{ backgroundColor: filterdBy === "completed" && "red" }}
onClick={(_) => filtereTodos("COMPLETED")}
>
Completed
</button>
<button
style={{ backgroundColor: filterdBy === "uncompleted" && "red" }}
onClick={(_) => filtereTodos("UNCOMPLETED")}
>
Uncompleted
</button>
</div>
setTodos(Array<Object>)The setTodos method to replace todos with passed todos. Useful for api data.
import { useTodo } from "react-use-todo";
const { setTodos } = useTodo();
const todos = [{
id: Date.now(),
text: 'first todo',
completed: false,
}]
setTodos(todos);
addTodo(Object)The addTodo method to add new todo.
import { useTodo } from "react-use-todo";
const { addTodo } = useTodo();
// these keys are mandatory to pass while adding your todo.
const todo = {
id: Date.now(),
text: 'first todo',
completed: false,
}
addTodo(todo);
toggleTodo(todoId: string | number)The toggleTodo method to toggle the completd state of todo.
import { useTodo } from "react-use-todo";
const { toggleTodo } = useTodo();
const todo = {
id: Date.now(),
text: 'first todo',
completed: false,
}
<input
id={todo.id}
type="checkbox"
value={todo.completed}
checked={todo.completed}
onChange={(e) => toggleTodo(todo.id)}
/>
updateTodo(todoId: string | number, text: string)The updateTodo method to update the text of todo.
import { useTodo } from "react-use-todo";
const { updateTodo, filterdTodos: { todos } } = useTodo();
updateTodo(todos[0].id, 'Update this');
removeTodo(todoId: string)The removeTodo method to remove todo.
import { useTodo } from "react-use-todo";
const { removeTodo, filterdTodos: { todos } } = useTodo();
removeTodo(todos[0].id);
FAQs
Light weighted hook to build todo app
We found that react-use-todo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.