An enchanced useState hook which keeps track of the states history, allowing you to undo and redo states.

Overview

useTimeline

An enchanced useState hook which keeps track of the states history, allowing you to undo and redo states.


useTimeline is a simple hook based on the useState hook which abstracts operations of undo and redo.

A full example is avaiable on here.

Install

With npm:

npm install @mr96/use-timeline

With yarn:

yarn add @mr96/use-timeline

Quick Start

import { useTimeline } from '@mr96/useTimeline';

export default function App() {
  const {
    // current state
    state,
    // set a new state (same API as setState)
    setState,
    // undo by 1 step
    undo,
    // redo by 1 step
    redo,
    // true if there is an undoable state
    canUndo,
    // true if there is a redoable state
    canRedo,
    ...additionalProps
  } = useTimeline('');

  const onChange = (event: ChangeEvent<HTMLInputElement>) => {
    setState(event.target.value);
  };

  return (
    <button disabled={!canUndo} onClick={() => undo()}>
      Undo
    </button>
    <input type="text" onChange={onChange} value={state} />
    <button disabled={!canRedo} onClick={() => redo()}>
      Redo
    </button>
  )
}
You might also like...

Remarkable is a simple extension that automatically keeps your bookmarks clean & up-to-date.

Remarkable is a simple extension that automatically keeps your bookmarks clean & up-to-date.

Remarkable Remarkable is a simple extension that automatically keeps your bookmarks clean & up-to-date. Installation (Other browsers coming soon - sor

Dec 21, 2022

Stale While Revalidated Resources — keeps data fast

swrr Stale While Revalidate Resource npm add swrr makes resources fast Caveat ~ Currently cache backplane is assumed to be Cloudflare Workers KV. Befo

Oct 24, 2022

Simple news reader that keeps the noise low.

Simple news reader that keeps the noise low.

Thud. Read news without the fuss · Report Bug · Request Feature Table of Contents About The Project Built With Getting Started Prerequisites Contribut

Jan 1, 2023

Bitcoin terminal tracker is a terminal app which allow you to track bitcoin price from your terminal

Bitcoin terminal tracker is a terminal app which allow you to track bitcoin price from your terminal

BTC Terminal Tracker Bitcoin terminal tracker is a terminal app which allow you to track bitcoin price from your terminal. In this version (V1.2) I ch

Jul 27, 2022

BCash is an app to help you keep track of who you owe and who owes you money in an easy way. Split your tabs and more.

BCash BCash is an app to help you keep track of who you owe and who owes you money in an easy way. Split your tabs and more. Routes for develpment: lo

Aug 11, 2022

Zemi is data-driven and reverse-routing library for Express. It provides out-of-the-box OpenAPI support, allowing you to specify and autogenerate an OpenAPI spec.

zemi zemi is a data-driven routing library for Express, built with Typescript. Features: optional, out-of-the-box support for OpenAPI reverse-routing

Jul 23, 2022

This is a dependency-free easy-to-use vanilla JavaScript addon allowing you to create HTML currency inputs with various different currencies and formattings.

intl-currency-input This is a dependency-free easy-to-use vanilla JavaScript addon allowing you to create HTML currency inputs with various different

Jan 4, 2023

A Svelte parser that compiles to Mitosis JSON, allowing you to write Svelte components once and compile to every framework.

Sveltosis Still in development A Svelte parser that compiles to Mitosis JSON, allowing you to write Svelte components once and compile to every framew

Nov 24, 2022

An obsidian plugin allowing you to register and view different file extensions in a modular manner.

Obsidian Custom File Extensions Plugin This is a plugin for Obsidian to allow associaton of file type extensions with different in-app views via setti

Dec 6, 2022
Releases(v1.4.0)
Owner
null
History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState

History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype.

Browser State 10.8k Dec 26, 2022
This is a simple app that keeps track of count. It also has a reset button that takes the count back to zero.

Counter This is a simple app that keeps track of count. It also has a reset button that takes the count back to zero. Built With HTML SCSS CSS Javascr

Abubakar Ummar 5 Oct 17, 2022
SafeCycle—a tool that keeps cyclists safe. Gone are days of weaving through busy city streets, SafeCycle finds all the bike routes for you to ensure a smooth ride wherever you want to go.

Inspiration Biking—an everyday form of travel for students and professionals across the globe. On-campus, back home, and with the people that we know

Ryan Hu 2 May 2, 2022
Awesome books is a vanilla Javascript which offers CRUD functionalities allowing you to add, remove edit boks info and store it to the local storage.

Awesome Books Awesome books is a simple project that displays new books when a user updates them. Built With HTML-5 CSS3 Javacript Linters Live Demo L

Nemwel Boniface 23 Aug 6, 2022
This is a single page web application that keeps tracks of books. Book details captured are the book title, author and ISBN. User can add a book, view a list of books and also remove any un wanted books.

Project Name This is a single page web application that keeps tracks of books. Book details captured are the book title, author and ISBN. User can add

Olivier 6 Nov 20, 2022
Website that keeps monitoring status of WAX account and TLM balance from alienworlds

✔️ Server is now live! [21-5-2021 10:30 GMT+7] ?? Updates on Server ‼️ Bandwidth limit reaches on morning of 21 May 2021 (+7) I want to thank you to e

Patiphol Pussawong 21 Nov 24, 2022
A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

A free and open source resume builder. Go to App What is this app all about? Reactive Resume is a free and open source resume builder that’s built to

Reactive Resume 9.7k Jan 3, 2023
Today began learn about MEAN stack first with Nodejs that is a server side form of javascript. Repository for track of Day by Day improvement track in new Skill.

NodeJs Today began learn about MEAN stack first with Nodejs that is a server side form of javascript. Repository for track of Day by Day improvement t

Rahul Bhati 4 Oct 14, 2022