React: Create a Controlled Input
See original GitHub issueChallenge Name
React: Create a Controlled Input
Issue Description
I think I have the correct code and it is working like it is supposed to, but I’m not passing the test.
Browser Information
Chrome 64 (64 Bit) Windows 10 Desktop
Your Code
class ControlledInput extends React.Component {
constructor(props) {
super(props);
this.state = {
input: ''
};
// change code below this line
this.handleChange = this.handleChange.bind(this);
// change code above this line
}
// change code below this line
handleChange(event){
this.setState({
input: event.target.value
})
}
// change code above this line
render() {
return (
<div>
{ /* change code below this line */}
<input onChange={this.handleChange} />
{ /* change code above this line */}
<h4>Controlled Input:</h4>
<p>{this.state.input}</p>
</div>
);
}
};
Screenshot
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Forms - React
An input form element whose value is controlled by React in this way is called a “controlled component”. Since the value attribute is...
Read more >React Controlled Components, the Hooks Way - Dmitri Pavlutin
The controlled component is a convenient technique to access the value of input fields in React. It doesn't use references and serves as...
Read more >Controlled and uncontrolled form inputs in React don't have to ...
A controlled input accepts its current value as a prop, as well as a callback to change that value. You could say it's...
Read more >React: Creating a Controlled Input - DEV Community
There's a skeleton of a component called ControlledInput to create a controlled input element. Component's state as a input property with a ...
Read more >What are controlled inputs with React? - Educative.io
The official documentation defines controlled inputs as: The React component that renders an element also controls what happens in that element on subsequent ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You forgot to add
value
toinput
:First step will be making a function that changes the state variable
input
.Add a
value
attribute which is equal to theinput
property of the component’sstate
. Then add anonChange()
event handler set to the handleChange() method.Remember to bind
this
to the function.And you can try with solution if you forget bindings in the constructor:
Hope reply for help.
Enjoy!