我正在创建一个反应配方应用程序。我正在使用 Edamam API(食物食谱)。如何将食谱卡路里转换/计算为每份的卡路里量?也许将它四舍五入到整数?
现在我的浏览器中的组件,Chrome 开发者工具,看起来像这样: props
{
calories:3033.2012500008163
image:"https://www.edamam.com/web-img/e12/e12b8c5581226d7639168f41d126f2ff.jpg"
ingredients: [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
title:"Chicken Paprikash"
new entry: ""
}
APP.JS(部分)
<div className="recipe-section">
{recipes.map((recipe) => (
//label ---- title
<Recipe
key={recipe.recipe.label} // cba ge it
title={recipe.recipe.label}
calories={recipe.recipe.calories}
image={recipe.recipe.image}
ingredients={recipe.recipe.ingredients}
/>
))}
</div>
食谱.JS
import React from "react";
import style from "./recipe.module.css";
const Recipe = ({ title, calories, image, ingredients }) => {
return (
<div className={style.recipe}>
<h1> {title} </h1>
<ol>
{ingredients.map((ingredient) => (
<ul> {ingredient.text} </ul>
))}
</ol>
<p> {calories} </p>
<img className={style.picture} src={image} alt="" />
</div>
);
};
export default Recipe;
谢谢你。如果您需要更多信息,请告诉我!