Advertisement
Smryk

Assignment - section 3

May 24th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <ol>
  3.           <li>Create TWO new components: UserInput and UserOutput</li>
  4.           <li>UserInput should hold an input element, UserOutput two paragraphs</li>
  5.           <li>Output multiple UserOutput components in the App component (any paragraph texts of your choice)</li>
  6.           <li>Pass a username (of your choice) to UserOutput via props and display it there</li>
  7.           <li>Add state to the App component (=> the username) and pass the username to the UserOutput component</li>
  8.           <li>Add a method to manipulate the state (=> an event-handler method)</li>
  9.           <li>Pass the event-handler method reference to the UserInput component and bind it to the input-change event</li>
  10.           <li>Ensure that the new input entered by the user overwrites the old username passed to UserOutput</li>
  11.           <li>Add two-way-binding to your input (in UserInput) to also display the starting username</li>
  12.           <li>Add styling of your choice to your components/ elements in the components - both with inline styles and stylesheets</li>
  13.         </ol>
  14.  
  15. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  16.  
  17. App.js:
  18.  
  19. import React, {Component} from 'react';
  20. import './App.css';
  21. import UserInput from './UserInput/UserInput';
  22. import UserOutput from './UserOutput/UserOutput';
  23.  
  24. class App extends Component {
  25.  
  26.   state = {
  27.     username: 'default'
  28.   }
  29.  
  30.   inputChangedHandler = (event) => {
  31.     this.setState({
  32.       username: event.target.value
  33.     })
  34.   }
  35.  
  36.   render() {
  37.     return (
  38.       <div>
  39.         <UserInput inputChange={this.inputChangedHandler} name={this.state.username}/>
  40.         <UserOutput username={this.state.username}/>
  41.         <UserOutput username={this.state.username}/>
  42.         <UserOutput username={'hardcoded username'}/>
  43.       </div>
  44.     )
  45.   }
  46. }
  47.  
  48. export default App;
  49.  
  50. @@@@@@@@@@@@@@@@@@@@@@@@@@@
  51.  
  52. UserInput.js:
  53.  
  54. import React from 'react';
  55.  
  56. const UserInput = (props) => {
  57.     return (
  58.         <input type="text" onChange={props.inputChange} value={props.name}/>
  59.     )
  60. }
  61.  
  62. export default UserInput;
  63.  
  64. @@@@@@@@@@@@@@@@@@@@@@@@@@@
  65.  
  66. UserOutput.js:
  67.  
  68. import React from 'react';
  69.  
  70. const UserOutput = (props) => {
  71.     return (
  72.         <p>Username: {props.username}</p>
  73.     )
  74. }
  75.  
  76. export default UserOutput;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement