react-refetch icon indicating copy to clipboard operation
react-refetch copied to clipboard

Automatic Refreshing - Change Url on each request.

Open luke-unifymonitor opened this issue 7 years ago • 2 comments

Hi,

First, great library - thanks.

I'm using Automatic Refreshing and would like to update the url before the request is made.

Would it be possible to have the url returned as a function? For example....

connect(({ refreshInterval }) => {
    return {
      dataFetch: {
        url: (props) => { return `http://foo.com/${new Date().getTime()}` }, 
        refreshInterval: refreshInterval
      }
    }
  })

...or should I be attempting this some other way.

Many thanks.

luke-unifymonitor avatar May 03 '18 14:05 luke-unifymonitor

Interesting proposal. I guess this would just work if we always allowed url to be a function. I'm not sure I'd want to pass in the props because they'd be the old values, but at least in your case, a no-arg function would work too. Or do you need the props too?

ryanbrainard avatar May 04 '18 06:05 ryanbrainard

Thanks Ryan.

My full use case is for a url which reads http://foo.com/{id}/{epoch} - The id would be the same across requests, but guess I would need that from the props. epoch would obviously change.

I thought this might do it...

connect((props) => {
    return {
      dataFetch: {
        url: (props) => { return `http://foo.com/${props.id}/${new Date().getTime()}` }, 
        refreshInterval: props.refreshInterval
      }
    }
  })

I didn't realise it would always result in the props having old values though. I'm not familiar with the code base - would that be a difficult thing to make happen?

luke-unifymonitor avatar May 04 '18 07:05 luke-unifymonitor