Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Create a folder in src called components to hold all our components
* Create the UserDetail and ListOfUsers functional components
* Import and use components in App
* Send the user array into Apps and then into ListOfUsers
* Send the user array into App and then into ListOfUsers
* Send the first user from the array down into the UserDetail component

### Do
Expand All @@ -32,11 +32,9 @@
* In onChange handler function, setState the searchText to the value from the textbox

### Do
* Create a variable called currentUser in index.js.
* Create a variable called currentUser in index.js.
* Define a function in index.js called selectUser that will take a user as a parameter and then set that user as the currentUser.
* Send this function down the child tree so that ListOfUsers can call it
* Change index.js to send currentUser down the child tree instead of App.js hard coding the first one
* Register click event for ListOfUsers view link, call the function sent into props by parents, supply the argument of whatever user was clicked on.
* Re render the components


File renamed without changes.
12 changes: 9 additions & 3 deletions src/App.js → src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import React from "react";
import logo from "./logo.svg";
import "./App.css";
import ListOfUsers from "./ListOfUsers";

function App() {
return (
<div className="App">
function App(props) {

return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<ul>
<ListOfUsers users={props.users} />
</ul>
</div>
);

}

export default App;
23 changes: 23 additions & 0 deletions src/components/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "./react";
import logo from "./logo.svg";

function Header(props) {
const userItems = props.users.map(function(user){
return (
<p>
{user.first_name};
{user.last_name};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

</p>
);
});
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo"
<h2>Welcome to React</h2>
{userItems}
</div>
);
}

export default Header;
16 changes: 16 additions & 0 deletions src/components/ListOfUsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from "react";
import UserDetail from "./UserDetail";

function ListOfUsers(props) {
const Users = props.users.map((user, index) => (
<UserDetail
first_name={user.first_name}
last_name={user.last_name}
key={index}
/>
))
return (
Users[0]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are only returning the first user... If you want to return all, wrap them in a

element.

)
}
export default ListOfUsers;
13 changes: 13 additions & 0 deletions src/components/UserDetail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";

function UserDetail(props) {
return (
<li>
{props.first_name}
&nbsp;
{props.last_name}
</li>
);
}

export default UserDetail;
File renamed without changes
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import App from "./components/App";
import "./index.css";
import users from "./users";


function render() {
ReactDOM.render(
<App />,
<App users={users} />,
document.getElementById("root")
);
}
Expand Down
Loading