0

How to unmount. Return does not work. I need to be able to press button and after function completes then the function will be remove from the button


  const handleSubmit = () => {
    ipcRenderer.send(
      "EDITOR",
      [ type, typeValue],
      "editor_response"
    );
    onClose(selectedValue);
  };

  return <div>
    <Button onClick={handleSubmit} color="primary">
      Ok
    </Button>
  </div>
1
  • 1
    Add hasBeenClicked: false to the state, update it to true after the first click and check its value on the next clicks to exit the function. Commented Apr 2, 2021 at 21:50

1 Answer 1

1

Probably the cleanest solution is a state variable that determines whether the handler should be active or not.

const MyComp = () => {

  const [pressed, setPressed] = useState(false;

  const handleSubmit = () => {
    setPressed(true);
    ipcRenderer.send(
      "EDITOR",
      [ type, typeValue],
      "editor_response"
    );
    onClose(selectedValue);
  };

  const noop = () => {};
  
  return <div>
    <Button onClick={!pressed ? handleSubmit : noop} color="primary">
      Ok
    </Button>
  </div>;
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.