import React, { Component } from 'react';
import './App.css';
import UserInput from './UserInput/UserInput'
import UserOutput from './UserOutput/UserOutput'
import "./UserOutput/UserOutput.css"
class App extends Component {
state = {
usernames: [
{ name: "name1" },
{ name: "name2" }
]
}
onButtonClicked = () => {
this.setState({
usernames: [
{ name: "name 11111" },
{ name: "name 22222" }
]
})
}
onTextChanged = (event) => {
this.setState({
usernames: [
{ name: event.target.value },
{ name: "name 22222" }
]
})
}
render() {
return (
- Create TWO new components: UserInput and UserOutput
- UserInput should hold an input element, UserOutput two paragraphs
- Output multiple UserOutput components in the App component (any paragraph texts of your choice)
- Pass a username (of your choice) to UserOutput via props and display it there
- Add state to the App component (=> the username) and pass the username to the UserOutput component
- Add a method to manipulate the state (=> an event-handler method)
- Pass the event-handler method reference to the UserInput component and bind it to the input-change event
- Ensure that the new input entered by the user overwrites the old username passed to UserOutput
- Add two-way-binding to your input (in UserInput) to also display the starting username
- Add styling of your choice to your components/ elements in the components - both with inline styles and stylesheets
);
}
}
export default App;
===== UserInput.js =====
import React from 'react';
const userInput = (props) =>{
return (
)
}
export default userInput;
===== UserOutput.js, UserOutput.css =====
import React from 'react';
import './UserOutput.css';
const userOutput = (props) => {
return (
paragraphs 1: name is {props.name}
paragraph 2
)
}
export default userOutput;
.UserOutput{
border: 1px solid black;
background-color: #eee;
margin: 10px
}