CodeNewbie Community 🌱

Discussion on: What's something you're struggling with?

Collapse
 
j3ffjessie profile image
J3ffJessie

Right now I’m struggling with how I’m going to pull data from two different API requests into one component and serve that data to a chart library for use. Currently I have one request serving data and utilizing it with the chart but haven’t set my head right on how to handle the second request and serving that data. State management and ensuring the second request doesn’t get repeated multiple times is key and I’m having a little difficulty wrangling my thoughts on it currently.

Collapse
 
nickytonline profile image
Nick Taylor • Edited

If you're making the two API calls and the second call doesn't depend on the first, use Promise.all. I'm assuming you're referring to a JS framework like React or Vue based on

pull data from two different API requests into one component

Not really understanding the second request being called multiple times potentially though. I'd need more context.

Collapse
 
j3ffjessie profile image
J3ffJessie

Right on. Using React, Axios has their own Axios.all that can handled the promise stuff. Trying to figure out a way to limit one call to only run once. The data will stay the same for one API request but the other request is handled by user input. Appreciate your advice.