React - example of toggle button with onClick

0 votes
142 views
added Apr 14, 2021 in React by lcjr First Warrant Officer (11,930 points)
const agentPhone = data.agent ? data.agent.contact_s : '';
const phone = 60 + agentPhone;
const zip = agentPhone.substring(0, 3);
const middle = agentPhone.substring(3, 6);
const last = agentPhone.substring(6, 11);
const maskNumber = `${zip} ${middle} XXXX`;
const unMaskNumber = `${zip} ${middle} ${last}`;
const [Phone, togglePhone] = useState({
  value: maskNumber,
  isMask: true,
});

  return (
  <span>
    {Phone.isMask === true ? (
      <a className="agent-tel" href="" onClick={e => toglPhone(e)}>
        {maskNumber}
      </a>
    ) : (
      <a className="agent-tel" href={`tel:${unMaskNumber}`}>{unMaskNumber}</a>
    )}
  </span>
  );
}

export default AgentTop;

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...