r/reactjs • u/timmonsjg • Dec 03 '18
Needs Help Beginner's Thread / Easy Questions (December 2018)
Happy December! βοΈ
New month means a new thread π - November and October here.
Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! Weβre a friendly bunch. No question is too simple. π€
π Want Help with your Code? π
- Improve your chances by putting a minimal example to either JSFiddle or Code Sandbox. Describe what you want it to do, and things you've tried. Don't just post big blocks of code!
- Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.
Have a question regarding code / repository organization?
It's most likely answered within this tweet.
New to React?
π Here are great, free resources! π
38
Upvotes
View all comments
2
u/codebrewja Dec 10 '18
New to REACT, trying to make a grocery-list app that uses recipes to add ingredients to a list. I have a basic question about calling data from an api that has other nested data that needs to be mapped over. Basically the API calls a recipe, which has ingredients (the array I initially mapped over), and inside there are other data points that I want, and not others.
It looks something like this for what I want:
this.state = {ingredients: [{name:amount:measurement:}]}The data looks like this:
recipe: {extendedIngredients: [name: ''name'',measure: {us: {amount: "1",unitShort: "string"}}]}I need only the specific data to be pushed into this array of ingredients. I don't really know how to deal with it from the front end where I want to configure each ingredient with only the name, amount and measurement going into the object. From what I understand state is immutable so I can't just make an object and push it into an array? Even still, I am not sure how I'd do that within a component.