How to refresh a Cell due to stale data?

I have a queue of items I’m hydrating in a Cell, with the first item in the queue being the showcased item and the remaining being under a “next up” list. The Cell makes a GET request to a third-party API in the background to get the data based on this tutorial.

There is a countdown associated with each item in the queue, and I’m using react-countdown to display this countdown for only the showcased element. When that countdown completes and the next item in the queue is to be showcased, I want the Cell to refresh and rehydrate as the prior data could be stale.

I’m quite new to both React and RedwoodJS so I’m not sure if this is something that should be handled based on the React lifecycle or Redwood APIs. I looked into calling refetch, but kept getting errors. What do you recommend?

Below is a simplified snippet of my code:

const renderer = ({ hours, minutes, seconds, completed }) => {
    if (completed) {
        // do some refreshing here?
    } else {
        return <span>{hours}:{minutes}:{seconds}</span>

export const Success = ({ mapRotation }) => {
    return (
                Currently <span class="current-map">{}</span> <span class="current-map-time">for <Countdown date={[0].start} renderer={renderer} />

            <table className="schedule-table">
               => {
                            let startTime = dayjs(upcoming.start);

                            return (
                                    <td>{startTime.format('MM/DD hh:mm A')}</td>

Hey @sachanganesh :wave:

It sounds like the refetch prop might be able to help you here. Along with the data (mapRotation in your example) returned from the query, a Cell’s Success component actually gets passed a lot of props; refetch is one of them.

So you could try something like…

export const Success = ({ mapRotation, refetch }) => {
  return (

    Currently ... <Countdown ... renderer={() => renderer({ refetch })} />

Modifying rerenderer to call refetch in the if (completed) clause.

Here’s the associated apollo docs on the topic for good measure:

Let me know if it works!


That was brilliant, thanks so much!

I didn’t know that’s how you’re supposed to import refetch, and it makes more sense now. I was trying to use useMutation and useState to help me refresh the data, but this way is so much easier.

Thanks again!