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

132
Vistas
React - Update custom hook's ref in a component

I have implemented the following custom hook:

export default function useCamera() {
   const [cameraRatio, setCameraRatio] = useState(Camera.Constants.DesiredRatio);
   const [cameraType, setCameraType] = useState(Camera.Constants.Type.back);
   const [flashMode, setFlashMode] = useState(
      Camera.Constants.FlashMode.off
   );

   const camRef = useRef(null); <----- Interesting part
   const cameraTypeRef = useRef(cameraType);
   const isTakingPhoto = useRef(false);

   const takePhoto = () => {
      if(!camRef.current) return; <----- Interesting part

      ...
   }

   const flip = () => {}

   const toggleFlash = () => {}

   ...

   return {
      camRef,
      cameraRatio,
      cameraType,
      flashMode,
      takePhoto,
      flip,
      toggleFlashMode,
      ...
   }
}

So, in my Camera component, I just do:

function Camera({ ... }) {
   const {
      camRef, <---- Interesting part
      takePhoto,
      ...
   } = useCamera();
  
   return <NativeCamera ref={camRef} onTakePhoto={takePhoto} ... />
}

As you can see, I am passing the camRef to "NativeCamera". This ref is defined in my custom hook "useCamera", and received in my "Camera" component, which just pass the ref to the child.

But this doesn't work. Any workaround?

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