Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
<Image> view the old picture even after capturing a new picture using react-native-vision-camera

I'm using react-native-vision-camera to capture a picture and view it inside an <Image> component. The expected behavior is updating the picture after capturing a new one. Since the source property of the <Image> component points to a new picture (with the same name Ok, but still, it's a new picture).

But this never happens. Even when I reload the app, <Image> still shows the old picture. I have to rename the new picture.

I thought that this happens because maybe the state of the source property updates before react-native-vision-camera saves the new picture so the <Image> component renders the old picture but I'm using async-await so as far as I know, this shouldn't happen.

The code I wrote for the capturing function is

const [photoPath, setPhotoPath] = useState("");

const capture = async () => {
        const photo = await camera.current.takePhoto();
        const path = RNFS.ExternalDirectoryPath + '/photo-X.jpg';
        //when i update X (in the saved image name) with a new number,
        //<Image> views the correct image.

        await RNFS.moveFile(photo.path, path)
        setPhotoPath("file://" + path)
    }

the code to view the image

{
    photoPath.length > 0 ?
        < Image
          source={{ uri: photoPath }}
          style={[styles.camera, { backgroundColor: 'black' }]}
        />
    :
        null
}

I have a capture <Button> that calls the capture() function that updates the photoPath state that should update the source of the <Image> component and this process should view the new picture. But this never happens even after reloading the app. I have to pick a new name for the new picture to get it to be viewed. Why I'm getting this behavior instead of the one I'm expecting? What's wrong with my code, or my understanding, and what is the correct solution?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After a day of searching and debugging, I found out that <Image> for a reason that I don't know, renders the cashed image. And since there is no easy way to delete cash in react-native, this is a work-around that solved my problem.

< Image
    source={{ uri: photoPath + "?" + new Date() }}
    style={[styles.camera, { backgroundColor: 'black' }]}
/>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!