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

159
Views
is there any way to usestate respond immediately?

I was wanting to get value from the my server of the node with the usestate, but it returns the empty array value first and then pops up the value of my axios

has any way of the value of the axios appears first than that of the empty array ?

my code:

const [valTop, valTopstate] = useState([])

    async function MusicTop() {
        axios("http://localhost:3001/")
        .then(res=>{
            valTopstate(res.data.tracks.data)
        })
    }
    
    useEffect(()=>{
        MusicTop()

    }, [valTop])

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

0

Your code is fine but UseEffect is executed only after the component is rendered, so you can apply a logic that is the array is empty then show the loader and if not show the array values, and if this is your child component what you can do is that when this child component is going to be executed then you can first fetch the required array value by calling a function in the parent component and pass the values as props in the child component.

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!