Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda