0

So here is my code:

<img src={currentQuestion?.GIF_URL} key={`${GIF_URL}-${currentIndex}`} alt='gif' style={{margin: '0 auto'}} />

As you can see I've added in a key to tell React to trigger a re-render and this has worked with my audio files but is not working with my gif url to my appwrite storage bucket.

I've tried adding in a key to trigger a re-render and I was expecting it to update and re-render just my this component:

<audio key={audio_URL} controls autoPlay>
            <source src={audio_URL} type="audio/mp3" />
                    </audio>
4
  • How do you update audio_URL? Commented Apr 15 at 18:53
  • Hey thanks for responding. I update it like this: <audio key={audio_URL} controls autoPlay style={{ opacity: '0', position: 'absolute' }}> <source src={audio_URL} type="audio/mp3" /> </audio> Commented Apr 15 at 20:10
  • This is using the destructured context variable that will update and trigger a re-render: const {questionText, audio_URL, Section, Type, GIF_URL } = currentQuestion; Commented Apr 15 at 20:11
  • 1
    Is the image src url changing? If not the browser might be caching the url. Commented Apr 15 at 20:13

1 Answer 1

0

So I found a workaround. I realised that the GIF url context variable was not being updated.

So in the context hook I extracted the array of urls from the backend and I added that in as another context variable.

Then I used a currentIndex variable that is I used in the context to move to the next question to access the elements in my urls array.

That way I just extracted the urls and put them in an array and then passed that through context and looped through the array to extract the relevant gif url

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.