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

220
Views
React & Mobx - invoking API calls best practices

I'm very new to React / Mobx. I would like to incorporate best practices from the get-go. I've built out several different components with various data types and API calls.

One of the concerns I have is the way I've implemented the useEffect in my components. I have several components that render the same state store and make the same call to fetch the data from the same API. If I include these components in the same page, each component will invoke a call to the same API, essentially fetching the same data N number of times.

For example:

const AlertsVisualization = ({ id }) => {

    useEffect(() => {
        alertsStore.getAlertsForId(id);
    }, [id]);

    return (
        // render a visualization
    )
}

export default observer(AlertsVisualization)
const AlertsList = ({ id }) => {

    useEffect(() => {
        alertsStore.getAlertsForId(id);
    }, [id]);

    return (
        // render a list
    )
}

export default observer(AlertsList)

In this example, I have two components that use the same state store but render it slightly different. If I include both of these components on the same page, it will invoke the getAlertsForId(...) twice, thus creating two separate calls for the same exact data.

So my question is, where should I be invoking the getAlertsForId(...) function?

about 4 years ago · Juan Pablo Isaza
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!