Created
December 12, 2018 23:49
-
-
Save aerrity/2844a31192268100485eede6bea4a7b6 to your computer and use it in GitHub Desktop.
Revisions
-
aerrity created this gist
Dec 12, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ import React from "react"; import ReactDOM from "react-dom"; // This loads data from a file named 'data.json' in the same directory import data from "./data"; // Store the array of user objects in a variable const users = data.results; // [{user},{user}, ...] // Component to represent a single User 'Card' (note: this is a function component so cannot use state) function User(props) { return ( <div> <img alt="Profile" src={props.image} /> <h2>{props.name}</h2> <p>{props.quote}</p> </div> ); } // Iterate across all elements (u) in the users array, producing a User component for each // Data is passed into the components via props const userList = users.map(u => ( <User key={u.name.first} name={u.name.first} image={u.picture.medium} quote={u.quote} /> )); // Render all the User components in a 'grid' layout ReactDOM.render(<div>{userList}</div>, document.getElementById("root"));