Skip to content
Advertisement

How can I conditionally map multiple arrays with if statements after fetching an array of objects? (React)

This is all in Prescriptions.js

I am fetching a bunch of prescription drugs from my api.

JavaScript

After that’s done, I want to make a category array based on drug.class and render it down there. If that category already exists, then push the drug into it’s category’s array, if it doesn’t, make a new array based on that category, push the drug into that array, and render it as shown.

JavaScript

I’ve been trying to get this done for days and I am stuck, would appreciate some help!

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement