const ContactDetails = () => { const state = useAppSelector((state) => state.data);…
- User
const ContactDetails = () => { const state = useAppSelector((state) => state.data); const useChangeCopiedStateToDefaultAfter = (time: number) => { const [copied, setCopied] = useState(false);
useEffect(() => { const timeout = setTimeout(() => { if (copied) setCopied(false); }, time); return () => clearTimeout(timeout); }, [copied]); return [copied, setCopied]; }; return ( <a href={
tel:${state.phone}}> <p onClick={() => { setCopied(true); copyEmail(state.email); }} > {state.email} <a href={tel:${state.phone}}> {state.phone} author: {state.author} description: Front-End Developer git: {state.gitHub} ); };export default ContactDetails; why ther is an This expression is not callable. Not all constituents of type 'boolean | Dispatch<SetStateAction>' are callable. Type 'false' has no call signatures.ts(2349)
- Assistant
The error message is due to the fact that the variable
setCopiedis not defined within the scope of the component. It needs to be declared using theuseStatehook before being used within theonClickhandler. Here's an updated version of the code with the necessary changes:const ContactDetails = () => { const state = useAppSelector((state) => state.data); const [copied, setCopied] = useChangeCopiedStateToDefaultAfter(2000); return ( <section className="contactDetails"> <article className="phoneAndEmail"> <figure> <a href={`tel:${state.phone}`}> <img src={Images.contact} alt="contact" /> </a> </figure> <article className="phoneAndEmail__text"> <div> <p onClick={() => { setCopied(true); copyEmail(state.email); }} > {state.email} </p> <Clipboard copied={copied} setCopied={setCopied} text={state.email} color="black" /> </div> <a href={`tel:${state.phone}`}> <p>{state.phone}</p> </a> </article> </article> <article className="descr"> <figure className="descr__photo"> <img src={Images.devPhoto} alt="developer" /> </figure> <p>author: {state.author}</p> <p>description: Front-End Developer</p> <a target="_blank" href={state.gitHub}> <p>git: {state.gitHub}</p> </a> </article> </section> ); }; export default ContactDetails;Note that
useChangeCopiedStateToDefaultAfteris an example custom hook that is assumed to be correctly defined in another part of the code.