M
M
myskypesla2018-10-29 10:50:21
React
myskypesla, 2018-10-29 10:50:21

How to fix the simultaneous call of 2 or more identical functions?

Hello, I have an application that has 2 components that can be shown simultaneously on the page together or separately. In the second case, everything is OK, but in the first case, there is a problem of double calling the data request function in the API.
Here is an example of the implementation of two identical requests: https://codesandbox.io/s/14q587x107
Question: how to get rid of this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mShpakov, 2018-10-29
@mShpakov

store data in vuex

A
Aleksey Solovyev, 2018-10-29
@alsolovyev

Why are you writing the same code twice?

fetch("https://jsonplaceholder.typicode.com/users")
      .then(response => response.json())
      .then(json => console.log(json));

Transfer the request to the parent (index.js) and pass the received data to the components ( props )
Something like this https://codesandbox.io/s/pkvw21276x

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question