Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
React how to use setInterval with useEfecct and axios request

Where I've to use setInterval to fetch every second? When i try it i get this error Uncaught SyntaxError: Unexpected identifier

  useEffect(() => {
    const getHistory = async () => {
      const res = await axios.get('/api/payment', {
        headers: { Authorization: token },
      });
      setHistory(res.data);
    };
    getHistory();
  }, [token, delivered]);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use swr for this and benefit from not only built-in revalidation on interval, but also caching and deduplication.

import useSWR from 'swr'

// You can use axios if you want
const fetcher = (...args) => fetch(...args).then(res => res.json())

const { data, error } = useSWR('/api/payment', fetcher, { refreshInterval: 1000 })

if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div>
return <div>Look at all this data: {data.someProperty}</div>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!