Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
I want this code to undo/redo user action which worked as wanted but after the undo/redo is completed and I undo/redo again I get an error

The error state > Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'undo') History.undo

please how can I implement a code to undoDisable and redoDisabled that would make my code stop running once the last undo/redo have been triggered so I don't get the error again**

below is my code that handles the undo and redo action

  const handleUndokey = async (e: KeyboardEvent) => {
    const zKey = 'z';
    if (e.ctrlKey && e.key === zKey) {
      designer.clearSelectedElements();
      await history.undo();
      dispatch(updateDesigner(designer));
      saveDesigner();
    }
  };

  useEffect(() => {
    document.addEventListener('keydown', handleUndokey);
    return () => {
      document.removeEventListener('keydown', handleUndokey);
    };
  }, []);

  const handleRedoKey = async (e: KeyboardEvent) => {
    const yKey = 'y';
    if (e.ctrlKey && e.key === yKey) {
      designer.clearSelectedElements();
      await history.redo();
      dispatch(updateDesigner(designer));
      saveDesigner();
    }
  };

  useEffect(() => {
    document.addEventListener('keydown', handleRedoKey);
    return () => {
      document.removeEventListener('keydown', handleRedoKey);
    };
  }, []);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!