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

142
Views
React native Pull to refresh is not working

I m trying to add pull to refresh to fetch my data from my api but it is not working and i can'y find the problem within the code:

 const[refresh,setRefresh]=useState(true)

  const onRefresh=()=>{
    try{
      axios
      .get('http://192.168.1.17:8000/File/')
      .then((response)=> {
         
          setFile(response.data);
          setFilteredFile(response.data)
          setEmpty(false)
          setRefresh(false);
  
  
      })}
      catch(error){console.log(error)          
      }
  }

useEffect(()=>{
    onRefresh()      
  },[])

  <FlatList style={DocumentStyle.flatstyle}
              keyExtractor={(item)=>item['id']}
              data={filteredfile}
              renderItem={renderItem}
              onRefresh={()=>onRefresh()}
              refreshing={refresh}
              />

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

never mind me everyone, i haven't set my refresh back to true after the useEffect set it to false

about 4 years ago · Juan Pablo Isaza Report

0

The error is due to not importing useState, but you also need to import useEffect. I also dont see where some of the props your passing to FlatList are being used. But here's a working sample:

import {useState, useEffect} from 'react';

const FlatList = ({file, refreshing, onRefresh}) => {
return (
  <div>
    <p>{file}</p>
    <button onClick={() => onRefresh(2)}>Load another todo</button>
  </div>
 )
}

export default function App() {
const [refresh, setRefresh] = useState(true);
const [file, setFile] = useState('');

useEffect(() => onRefresh(), []);

const onRefresh = (id=1) => {
 try {
   fetch(`https://jsonplaceholder.typicode.com/todos/${id}`)
   .then(response => response.json())
   .then(json =>  {
     console.log(json)
     setFile(JSON.stringify(json))
     setRefresh(false);
   })
 }
 catch(error) {
   console.log(error);         
 }
}

  return <FlatList file={file} refreshing={refresh} onRefresh={onRefresh} />
}
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!