Я хочу создать приложение для тренировки, поэтому я создал файл JSON, который имеет "имя-упражнения" и "описание" (я просто играю с реакцией)
1-й, я создал компонент под названием "ExerciseCard"
import React from 'react'
function ExerciceCard(props) {
return(
<h1>this is the exercie {props.exerciceName}</h1>
)
}
export default ExerciceCard
и затем я создал страницу с именем CreateNewWorkout
import React from 'react'
import ExerciseCard from '../component/ExerciseCard'
class CreateNewWorkout extends React.Component {
state = {
exercises : []
}
async componentDidMount() {
let response = await fetch("http://localhost:1337/calisthenics-exercices")
const data = await response.json()
//i wanted to loop throgh the array of and push the exerciceName to the exercise state array
for (let i = 0; i <data.lenght; i++) {
this.setState({exercices : [...this.state.exercises, data[i].exeriseName]})
}
}
render() {
return(
<>
<ExerciseCard exerciceName = {this.state.exercice} ></ExerciseCard>
</>
)
}
}
export default CreateNewWorkout
В настоящее время у меня есть два "упражнения" в файле JSON, и я хочу знать, как отрисовать ExerciseCard
компонент два раза (в данном случае).