-1

I would like to refresh data every 1 second. But this code below is not working.

  const fetchSupplyInfo = (slice, accounts) => (...args) => {
      const vSupply =  slice.methods.sliceParams().call({ from: accounts[0] }).then((data) => {return data[0]})
      return vSupply
  }
  const { data: vSupply, error2 } = useSWR('supplyInfo', {fetcher: fetchSupplyInfo(slice, accounts)}, { refreshInterval: 1000 })
      console.log('vSupply', vSupply)
juliomalves
  • 42,130
  • 20
  • 150
  • 146
Stano
  • 9
  • 1
  • Second argument passed to `useSWR` has to be a function, your passing an object. Try changing it to `useSWR('supplyInfo', () => fetchSupplyInfo(slice, accounts), { refreshInterval: 1000 })`. – juliomalves Nov 09 '21 at 23:19
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 10 '21 at 23:03

1 Answers1

0

Solved. Thank you for inspiration. I looked again in the documentation and this worked:

  const fetchSupplyInfo = (slice, accounts) => {
      const vSupply =  slice.methods.sliceParams().call({ from: accounts[0] }).then((data) => {return data[0]})
      return vSupply
  }

  const { data: vSupply, error2 } = useSWR([slice, accounts],fetchSupplyInfo, { refreshInterval: 1000 })
      console.log('vSupply', vSupply)
Stano
  • 9
  • 1