import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
class Example extends Component {
handler = () => {
this.props.history.push('/cources');
};
render() { /* ... */ }
}
export default withRouter(Example);
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
class Example extends Component {
render() {
return <Link to="/cources" />;
}
}
export default Example;
class Example extends Component {
state = {
inputValue: '',
};
handleChange = e => {
const { name, value } = e.target;
this.setState({
[name]: value,
});
};
handleSubmit = e => {
e.preventDefault();
// получить состояние формы можно обратившись к this.state
};
render() {
const { inputValue } = this.state;
return (
<form onSubmit={this.handleSubmit}>
<input
name="inputValue"
value={inputValue}
onChange={this.handleChange}
/>
...
</form>
);
}