input with button react code example
Example 1: react how to pass the input target value
class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: ''};
this.handleChange = this.handleChange.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
render() {
return (
<form>
<label>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
);
}
}
Example 2: setimeout react button
import React, { useEffect, useState } from 'react';
const TimeoutExample = () => {
const [count, setCount] = useState(0);
const [countInTimeout, setCountInTimeout] = useState(0);
useEffect(() => {
setTimeout(() => {
setCountInTimeout(count);
}, 3000);
setCount(5);
}, []);
return (
<div>
Count: {count}
<br />
setTimeout Count: {countInTimeout}
</div>
);
};
export default TimeoutExample;