npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-use-todo

v0.7.0

Published

Light weighted hook to build todo app

Readme

Why?

  • Bundle size
  • No dependencies
  • 🔥 Persistent todos with local storage, or your own adapter
  • ⭐️ Supports multiples todos per page
  • 🥞 Works with Next, Gatsby, React

Quick Start

Demo

Install

npm install react-use-todo # yarn add react-use-todo

TodoProvider

You 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.

Usage

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")
);

Props

| 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]. |

useTodo

The useTodo hook exposes all the getter/setters for your todo state.

loading: boolean

The loading variable gives you loading state. Useful for async task.

Usage

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.

Usage

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.

Usage

import { useTodo } from "react-use-todo";

const { todos } = useTodo();

<ul>
  {todos.map(todo => <li key={todo.id}>{todos.text}</li>)}
</ul>

filterdTodos: Object

The filterdTodos filtered array based on the selected filter.

Usage

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)

Usage

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.

Usage

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.

Usage

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.

Usage

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.

Usage

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.

Usage

import { useTodo } from "react-use-todo";

const { removeTodo, filterdTodos: { todos } } = useTodo();

removeTodo(todos[0].id);