I want to add json data to 4ColorCards like the pic,but title``color``rating fail the render,please see the code below:
ColorCards
title``color``rating
import ColorCard from "./ColorCard" import React from "react" import data from "./initialState.json" export default function ColorCards(){ const dataColors=data.colors return( dataColors.map( (n,color)=>( <ColorCard key={color.id} title={color.title} color={color.color} rating={color.rating} /> ) ) ) }
The full project link:https://codesandbox.io/s/material-demo-forked-62eh0?file=/index.js
Here is the working sandbox.
All I do is converting from (n,color)=>( to (color)=>(
(n,color)=>(
(color)=>(
Read more about how map works here
map
2.1m questions
2.1m answers
60 comments
57.0k users