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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
"private": true,
"devDependencies": {
"babel-eslint": "^7.1.1",
"eslint": "^3.14.0",
"eslint": "^3.19.0",
"eslint-plugin-babel": "^4.0.1",
"eslint-plugin-react": "^6.9.0",
"react-scripts": "0.7.0"
},
"dependencies": {
"foreman": "^2.0.0",
"json-server": "^0.9.4",
"prop-types": "^15.5.8",
"react": "^15.3.2",
"react-dom": "^15.3.2"
},
Expand All @@ -24,5 +25,5 @@
"test": "npm run lint && react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy" : "http://localhost:3001"
"proxy": "http://localhost:3001"
}
51 changes: 42 additions & 9 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
import React from "react";
import logo from "./logo.svg";
import "./App.css";
import Header from "./components/Header.js";
import Intro from "./components/Intro.js";
import PropTypes from "prop-types";

// This loops through the list of users and gathers info about them (first last)
// It creates a paragraph for each and returns that information to userItems
// Paragraph needs the key because it needs to know the same
// list is present even if it has been reordered.
// Since react monitors for changes, if I reorder the list
// in some way it would need to run through all users again.
// By giving it a key of the user ID, I ensure that
// even if the list changes order react has some anchor point for
// it to realize this is the same list as before, saving in performance.
// As long as this key has not changed, do not recalculate the list.

// Could have index as argument for userItems = function
// Changed App(props) to app({userArray}) to directly access userArray
// within the props object. (just shorthand)
function App({userArray}) {
const userItems = userArray.map(function (user) {
return (
<p key={user.id}>
First Name: {user.first_name + " "}
<br />
Last Name: {user.last_name}
<br />
Phone: {user.phone}
<br />
</p>
);
});

function App() {
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>
<Header message="some message" />
<Header message="some other message" />
{
// Display all the information I gathered from user items.
}
{userItems}
<Intro />
</div>
);
}

// Note lowercase propTypes method
App.propTypes = {
userArray: PropTypes.array.isRequired
};
export default App;
14 changes: 14 additions & 0 deletions src/components/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import logo from "./logo.svg";

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

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

function Intro() {
return (
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
)
};

export default Intro;
File renamed without changes
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import users from "./users";

function render() {
ReactDOM.render(
<App />,
<App userArray={users} />,
document.getElementById("root")
);
}
Expand Down
3 changes: 0 additions & 3 deletions src/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,3 @@ export default [
}

];



Loading