Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda