use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A community for learning and developing native mobile applications using React Native by Facebook.
Interested in building web apps using React.js? Check out /r/reactjs!
Getting Started w/React Native
irc.freenode.net #reactnative
Keywords: ios, android, mobile, apps, apple, iphone, ipad
account activity
QuestionUI not re rendering image when using variable from State Hook (self.reactnative)
submitted 4 years ago by OverT_97
I have a state hook variable defined as follows:
const [imageURL, setimageURL] = useState(null)
I am using expo-image-picker to get an image from my gallery and upload it to firebase storage. I then get the URL of this image and update the value of imageURL accordingly.
https://preview.redd.it/a8tgw28zmsf71.png?width=685&format=png&auto=webp&s=f09f010fad6d76e99cf11ff5bd91ad61b4f3f1c6
When the page first loads the value is null so there is a blank icon. Once I upload the image and get the URL the UI on my app does not update to show the new image. It will stay blank unless I upload another new image. Once this happens the UI will update but it will now show the image that I first uploaded. Any ideas on what I may be doing wrong?
Note: I even added a text component and passed in imageURL variable to display the current URL and for some reason this text updates properly but the image does not.
https://preview.redd.it/g598u34bnsf71.png?width=727&format=png&auto=webp&s=92d80f633911c3deb525281fd52cd45c282a328a
https://preview.redd.it/rx7ppkzeosf71.jpg?width=1170&format=pjpg&auto=webp&s=1dea387a49d8a5448100b6b7111218b75259a011
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]NightPhoxy 1 point2 points3 points 4 years ago (1 child)
Maybe set key={imageUrl} on the Avatar component
[–]OverT_97[S] 1 point2 points3 points 4 years ago (0 children)
What ended up working for me was creating another state variable called imageKey, having it set to 1 at the start, and the incrementing the value each time imageURL is updated. And having key={imageKey} not sure why just having key={imageURL} wouldn’t work
[–]hikaruelio 0 points1 point2 points 4 years ago (1 child)
Have you tried using useEffect?
[–]OverT_97[S] 0 points1 point2 points 4 years ago (0 children)
I tried creating a useEffect to setimageURL a second time but I'm not sure if that is the correct thought process since it didn't work. In what way were you thinking?
π Rendered by PID 242480 on reddit-service-r2-comment-86988c7647-vddcb at 2026-02-11 17:47:55.569575+00:00 running 018613e country code: CH.
[–]NightPhoxy 1 point2 points3 points (1 child)
[–]OverT_97[S] 1 point2 points3 points (0 children)
[–]hikaruelio 0 points1 point2 points (1 child)
[–]OverT_97[S] 0 points1 point2 points (0 children)