score:0

  const [popup, setPopup] = useState(null);

  async function GenerateElection() {
    setPopup(<Popup />)
    const election = await Axios
    .post("/addElection", {electionInfo}, {
       headers: { "token" : localStorage.getItem("token")}
      }
    );
    setPopup(null) // for hide
  }

  return (
    <div>
      {popup && popup}
      <Button variant="contained" style={{width: 150}} onClick={GenerateElection} >Generate Election</Button>
    </div>
  );

score:0

function GenerateElection() {
  popupRef.current.classList.add('show');

  Axios.post(*skipped part*).then(res => {
    const election = res.data
  });

<Button onClick={GenerateElection}>Generate Election</Button>

Related Query

More Query from same tag