Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda