I'm having trouble trying to save some data I'm getting from the CockTaiDB API into my Meteor Collection
state = {
randomCocktail: []
};
async componentDidMount() {
try {
const res = await fetch(
'https://www.thecocktaildb.com/api/json/v1/1/random.php'
);
const randomCocktail = await res.json();
this.setState({
randomCocktail: randomCocktail.drinks
});
} catch (e) {
console.log(e);
}
}
addDrink = (cocktail) => {
Drinks.insert({
name: cocktail.strDrink,
instructions: cocktail.strInstructions,
image: cocktail.strDrinkThumb
});
};
{this.state.randomCocktail.map((cocktail) => {
return (
<div key={cocktail.idDrink}>
<h1>{cocktail.strDrink}</h1>
{cocktail.strInstructions}
<img src={cocktail.strDrinkThumb} alt="" />
<button onClick={this.addDrink}>Add Drink</button>
</div>
);
})}
This is my function to save into the collection but all I'm getting is a new entry with an id. I used axios.get to retrieve the data, should I use axios.post somehow to save it into my Drinks collection?
Edit: State and api call. Map with the button to add name, image, and instruction.