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
utility function with useCallback

I have a simple function with a useCallback in three part of my app to set an image:

const myLittleFunction = useCallback((image: string | undefined) => {
    mySetState(image)
  }, [
    mySetState,
  ])

this function is used to retrieve an image of a child component:

<MyChildComponent
  setImage={setPickerResponse}
  />

But since I have 3 times the same one in three different places, how could I make it a single utility function?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I think you may need to move the STATE and the useCallback function in a custom hook, and you can use it in multiple places.

Ex:

export default () => {

  const [myState, setMyState] = useState('value here')
  const myLittleFunction = useCallback((image: string | undefined) => {
    mySetState(image)
  }, [
    mySetState,
  ])

  return {
    myState,
    setMyState,
    myLittleFunction,
  }

}
about 4 years ago · Santiago Trujillo Denunciar
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