Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

const ContactDetails = () => { const state = useAppSelector((state) => state.data);…

  1. 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)

  2. Assistant

    The error message is due to the fact that the variable setCopied is not defined within the scope of the component. It needs to be declared using the useState hook before being used within the onClick handler. 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 useChangeCopiedStateToDefaultAfter is an example custom hook that is assumed to be correctly defined in another part of the code.