Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

333
Visualizações
Error: React Hook "useCallback" is called conditionally. React Hooks must be called in the exact same order in every component render

Getting a build error usecallback hook called conditinally. if i dont use useCallback i get the error JSX props should not use arrow functions

const LinkComp = <T extends {}>(props: LinkProps & T extends AnchorProps ? AnchorProps : ButtonProps) => {
    const {
        title,
        hideTitle,
        children,
        url = '',
        action,
        label,
        newWindow,
        className,
        iconName,
        isExternal,
        inheritColor = true,
        underlineOnHover = true,
        underline = false,
        theme = '',
        bold = false,
        onClick,
        modal = false,
        forceAnchorTag = false,
        appendQueryParams = true,
        showOutline = true,
        ...linkProps
    } = props;
    const [handleClick] = useRouter(action, url);
    const forwardedParams = useSelector(selectForwardedQueryParams);

    const linkContent = (
        <>
            {iconName && <Icon name={iconName} className='mr-3' />}
            {!hideTitle && (title || children)}
        </>
    );

    if (modal) {
        if (linkProps.modalTitle) delete linkProps.modalTitle;

        return (
            <button {...(anchorProps as ButtonProps)} role='link' onClick={onClick as ButtonProps['onClick']}>
                {linkContent}
            </button>
        );
    }

    // queryString.stringifyUrl combines the params from both url and forwarded params.
    // don't append the params for `tel` links
    const forwardedParamsUrl = queryString.stringifyUrl({ url, query: !url?.includes('tel:') && forwardedParams });

    const handleAnchorClick = useCallback((e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) =>  {
        if (handleClick) handleClick(e);
        
        return true;
    },[handleClick]);

    if (forceAnchorTag) {
        return (
            <a href={forwardedParamsUrl} {...(anchorProps as AnchorProps)} onClick={handleAnchorClick}>
                {linkContent}
            </a>
        );
    }
    // search extras uses the query params in a different way, so no need to append them here
    const fullUrl = appendQueryParams ? forwardedParamsUrl : url;

    return (
        <Link href={fullUrl} passHref={isExternal || newWindow}>
            <a {...(anchorProps as AnchorProps)} onClick={handleClick}>
                {linkContent}
            </a>
        </Link>
    );
};

export default LinkComp;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to move your useCallback definition to above the if (model) check. This if block may cause your component to render before the function has been memoized by useCallback.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda