Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Draw on Undo #5

@Kyrixty

Description

@Kyrixty

Currently, the SketchPad does not re-draw on undo, only after the user draws on the canvas. This can be slightly annoying, so it makes sense for the canvas to re-draw on undo.

Can be implemented as:

export const SketchPad: FC<SketchPadProps & DrawPathOptions> = (props) => {
    // Initialization, setting state, etc.
    const [undoListener, setUndoListener] = useState(0);
    useEffect(() => {
        draw()
    }, [paths, draw, undoListener]);
    

    const handleUndo = () => {
        setPaths((currentPaths) => {
             currentPaths.pop();
             return currentPaths;
        }
        setUndoListener(undoListener + 1); // change state to trigger re-render
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions