-
Notifications
You must be signed in to change notification settings - Fork 50
russ.savage.atx.advanced.1 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
87c888b
8c0f3a3
efccdff
579e49f
f1abfd1
cdf2c2c
b5851c0
ed330f5
f5afac9
6dc208a
e8e5d4a
d04268e
13bf09f
1f3cbac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import React from "react"; | ||
| import logo from "./logo.svg"; | ||
| import "./App.css"; | ||
| import ListOfUsers from "./ListOfUsers"; | ||
| import UserDetails from "./UserDetails"; | ||
| import PropTypes from "prop-types"; | ||
|
|
||
|
|
||
|
|
||
| function App(props) { | ||
|
|
||
| return ( | ||
| <div className="App"> | ||
| <div className="App-header"> | ||
| <img src={logo} className="App-logo" alt="logo" /> | ||
| </div> | ||
| <div className="App-intro"> | ||
| <h2>User List</h2> | ||
| <ListOfUsers arrayOfUsers={props.arrayOfUsers} /> | ||
| <hr /><h2>User Details</h2><hr /> | ||
| <UserDetails arrayOfUsers={props.arrayOfUsers} /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| App.propTypes = { | ||
| arrayOfUsers: PropTypes.array | ||
| }; | ||
|
|
||
| export default App; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import React, {Component} from "react"; | ||
|
|
||
| class Button extends Component { | ||
| constructor() { | ||
| super(); | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <button>Show/Hide</button> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export default Button; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import React from "react"; | ||
|
|
||
|
|
||
| export default class Component2 extends React.Component { | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <h1>Component2</h1> | ||
| </div> | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import React, {Component} from "react"; | ||
| import PropTypes from "prop-types"; | ||
|
|
||
| class ListOfUsers extends Component { | ||
| constructor(props) { | ||
| super(props); | ||
| this.state = { | ||
| buttonClicked: false | ||
| }; | ||
| } | ||
|
|
||
| handleUserClick(event) { | ||
| console.log("Handle Click", event); | ||
|
|
||
| this.setState({ | ||
| buttonClicked: !this.state.buttonClicked | ||
| }); | ||
| } | ||
|
|
||
| render() { | ||
| if (!this.state.buttonClicked) { | ||
| return ( | ||
| <div> | ||
| <hr /> | ||
| {this.props.arrayOfUsers.map(user => { | ||
| return ( | ||
| <p key={user.id} onClick={this.handleUserClick.bind(this)} > {user.firstName} </p> | ||
| ); | ||
| })} | ||
| </div> | ||
| ); | ||
| } | ||
| return ( | ||
| <div> | ||
| <button onClick={this.handleUserClick.bind(this)}> | ||
| {this.state.buttonClicked ? "Show Names" : "Hide Names"} | ||
| </button> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // commented out old functional component once class component was built | ||
| // function ListOfUsers(props) { | ||
| // return ( | ||
| // <div> | ||
| // <hr /> | ||
| // {props.arrayOfUsers.map(user => { | ||
| // return ( | ||
| // <p key={user.id}> {user.firstName} </p> | ||
| // ); | ||
| // })} | ||
| // </div> | ||
| // ); | ||
| // } | ||
|
|
||
| ListOfUsers.propTypes = { | ||
| arrayOfUsers: PropTypes.array.isRequired | ||
| }; | ||
|
|
||
| export default ListOfUsers; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import React from "react"; | ||
| import * as Helpers from "../constants"; | ||
| import PropTypes from "prop-types"; | ||
|
|
||
|
|
||
| function UserDetails(props) { | ||
| // const selectUser = (array, index) => array[index]; | ||
| // commented out and saved in my "constants" folder | ||
| const {firstName, lastName, phone, address, occupation, avatar} = | ||
| Helpers.selectUser(props.arrayOfUsers, 0); | ||
| return ( | ||
| <div> | ||
| <img src={avatar} /> | ||
| <p>{firstName}</p> | ||
| <p>{lastName}</p> | ||
| <p>{phone}</p> | ||
| <p>{address}</p> | ||
| <p>{occupation}</p> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| UserDetails.propTypes = { | ||
| arrayOfUsers: PropTypes.shape({ | ||
| firstName: PropTypes.string.isRequired, | ||
| lastName: PropTypes.string.isRequired, | ||
| }) | ||
| }; | ||
|
|
||
| export default UserDetails; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export const selectUser = (array, index) => array[index]; | ||
| export const log = a => console.log(a); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing isRequired