Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
644 views
in Technique[技术] by (71.8m points)

reactjs - how to add json through mapping material-ui grid component

enter image description here

I want to add json data to 4ColorCards like the pic,but title``color``rating fail the render,please see the code below:

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

question from:https://stackoverflow.com/questions/65929940/how-to-add-json-through-mapping-material-ui-grid-component

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is the working sandbox.

All I do is converting from (n,color)=>( to (color)=>(

Read more about how map works here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...