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

180
Visualizações
I am trying to implement the addition and removal of the product but I get this error:Uncaught TypeError: props.handleFavouriteClick is not a function

this my file ProductCard.jsx Here I added a handleFavouriteClick to be equivalent to the passed function and to use it in the add and remove files


export default function ProductCard(props) {
  const { id, title, pictures, sizes,  } = props.product
  const [favored, toggleFavored] = useFavorite(id)

 

  return (
   <div className="group">
       <Heart
          className={cn(
            'h-4 w-4 mt-1 cursor-pointer stroke-1',
            favored
              ? 'stroke-red-400 fill-red-400 animate-like'
              : 'stroke-gray-600 ',
          )}
          onClick={()=> props.handleFavouriteClick(props.product)}
        />
      </div>
      <Link to={`/products/${id}`}>
        <h3 className="mt-2 text-base font-light text-gray-600">{title}</h3>
      </Link>
    </div>
  )
}

and this is Home.jsx .here I passed to handleFavouriteClick the function adding a product imported from another file.when I click on the heart, the above error comes out

  const theme = useTheme();
  const { data } = useSearchProductsQuery();
  const isTablet = useMediaQuery(theme.breakpoints.down("md"));
  const [addFavouriteProduct] = useFavorite(product)
 return (
    <Container className="pl-10 pr-10">
      <Banner />
      <InsChapter/>
       <Chapter/>
       <Chapter2/>
      {isTablet ? (
    <SearchFilter/>
    ): null}
      <div style={{display:'flex', justifyContent:'center'}}>
  {isTablet ? null : (
         <SearchFilterSideBar/>
       )}     
      <div className="grid grid-cols-2 mt-4 gap-y-5 gap-x-2 sm:gap-y-10 sm:gap-x-4 lg:grid-cols-3">
        {React.Children.toArray(
          data?.content.map(product => <ProductCard handleFavouriteClick={addFavouriteProduct} product={product}/>),        
        )}  
      </div>
      </div>
    </Container>
  ) 
}

Please help me.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think useFavorite() maybe returns many functions and variables. So if you want to use addFavouriteProduct function from useFavorite(), you should write like this.

const {addFavouriteProduct} = useFavorite(product)

Please try this. Best

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