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

194
Visualizações
calling a specific function to do a task inside React onClick Callback function

I am trying to do a specific task whenever an item is called. But this is compromising DRY principal so I tried to finish the work by using a function and got a React error! then tried to do it with CustomHooks but got the same error!! is there any way to avoid code code repetition

React Hook "useDeleteInventory" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function react-hooks/rules-of-hooks

callback function

onClick={() =>   useDeleteInventory(
                                item._id,
                                myInventories,
                                setMyInventories
                            )
                        }

CustomHook -

import axios from "axios";

const useDeleteInventory = async (id, inventories, setInventories) => {
const url = `http://localhost:5000/inventories/${id}`;
const proceed = window.confirm("Are you sure?");
if (proceed) {
    await axios.delete(url);

    const remainingInventories = inventories.filter(
        (inventory) => inventory._id !== id
    );
    setInventories(remainingInventories);

}
}
 export default useDeleteInventory
about 4 years ago · Juan Pablo Isaza
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