1.0.10 • Published 3 years ago

@nkavtaradze/use-undo-hook v1.0.10

Weekly downloads
48
License
ISC
Repository
github
Last release
3 years ago

Installation

Yarn

yarn add @nkavtaradze/use-undo-hook

NPM

npm install @nkavtaradze/use-undo-hook --save

Usage

import useUndo from'@nkavtaradze/use-undo-hook';
import { useState } from 'react';
function App() {

    const [count, setCount] = useState(0);
    const {
        element, 
        undo,
        redo,
        undos,
        redos,
        undoable,
        redoable,
    } = useUndo({
        value: count,
        setValue: setCount,
    })

    return (
        <div
            style={{
                textAlign: 'center',
            }}
        >
            <div>{count}</div>
            <div>
                <button
                    disabled={!undoable}
                    onClick={undo}
                >Undo</button>
                <button 
                    onClick={() => setCount(count + 1)
                }>Add</button>
                <button
                    disabled={!redoable}
                    onClick={redo}
                >Redo</button>
            </div>
        </div>
    );
}

export default App;
import useUndo from'@nkavtaradze/use-undo-hook';
import { useState } from 'react';


function App() {

    const [count, setCount] = useState(0);
    const {
        element, 
        undo,
        redo,
        undos,
        redos,
        undoable,
        redoable,
    } = useUndo({
        value: count,
        setValue: setCount,
    })

    return (
        <div
            style={{
                textAlign: 'center',
            }}
        >
            <div ref={element} tabIndex="0">
                Bind listeners here
            </div>
            <div>{count}</div>
            <div>
                <button
                    disabled={!undoable}
                    onClick={undo}
                >Undo</button>
                <button 
                    onClick={() => setCount(count + 1)}
                >Add</button>
                <button
                    disabled={!redoable}
                    onClick={redo}
                >Redo</button>
            </div>
        </div>
    );
}

export default App;
1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago