Created
February 7, 2023 11:39
-
-
Save wpflames/ef4e1b10397121f4fbf10286f58eeaed to your computer and use it in GitHub Desktop.
React - Passing state with props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import UserItem from './UserItem'; | |
class Users extends Component { | |
state = { | |
users: [ | |
{ | |
id: '1', | |
login: 'gabor', | |
avatar_url: 'https://avatars.githubusercontent.com/u/70385943?v=4', | |
html_url: 'https://github.com/wpflames', | |
}, | |
{ | |
id: '2', | |
login: 'jozee', | |
avatar_url: | |
'https://scontent.fbud6-4.fna.fbcdn.net/v/t31.18172-1/1272809_598671936858232_264280957_o.jpg?stp=c0.0.720.720a_dst-jpg_p720x720&_nc_cat=103&ccb=1-7&_nc_sid=7206a8&_nc_ohc=9QIznGl0cUkAX_OeAGe&_nc_ht=scontent.fbud6-4.fna&oh=00_AfDYNIfZuPN0YiPmYU5Qs7sPv9DKFMSCTXGmCx4fzC1OcQ&oe=6408A4D7', | |
html_url: 'https://github.com/mojombo', | |
}, | |
{ | |
id: '3', | |
login: 'peti', | |
avatar_url: | |
'https://scontent.fbud6-4.fna.fbcdn.net/v/t1.18169-1/155294_107908105949130_6506620_n.jpg?stp=c39.39.481.481a_dst-jpg&_nc_cat=110&ccb=1-7&_nc_sid=7206a8&_nc_ohc=ReleMTccozgAX_KzQFm&_nc_ht=scontent.fbud6-4.fna&oh=00_AfB6YSHKajEwEX-8eOhht7AqVJ8GtauuNAukXr5z874gUg&oe=64089650', | |
html_url: 'https://github.com/mojombo', | |
}, | |
], | |
}; | |
render() { | |
return ( | |
<div style={userStyle}> | |
{this.state.users.map((user) => ( | |
<UserItem key={user.id} user={user} /> | |
))} | |
</div> | |
); | |
} | |
} | |
const userStyle = { | |
display: 'grid', | |
gridTemplateColumns: 'repeat(3, 1fr)', | |
gridGap: '1rem', | |
}; | |
export default Users; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment