I have an array containing 'profiles' shown below. This is stored in a variable that is exported and I then want to render these in my component.
const people = [
{
name : "Chuck",
image : "./chuck.png",
skill : "Bowling"
},
{
name : "Arno",
image : './arno.png',
skill : "backflips"
}
]
export default people;
I import the variable (bare in mind it contains hundreds of data points) and in my components constructor I use the following,
constructor(props) {
super(props)
this.state = { data : people }
To render these I then use map to map these into a card component
render() {
let cards = this.state.data.map(function(elem, index) {
return (
<Card
name = {elem.name}
image = {elem.image}
skills = {elem.skill}
key = {elem.name}
zIndex = {1000-`${index}`}
/>
)
})
return (
<Card {pass in props (name, image, skills) to child Card component} />
My question is, is this bad practice? Everything works fine. The app is similar to a dating app UI where the first card, or element in the array is popped off and we are presented with the next card. How else would you pass in a large array to use and render elements in a component?
I hope its clear what i'm doing here. Thanks