I'm working on a project, most of its components are classes, but I need to use Hooks, so i need to get ride of the classes and convert them to functional components, I know the basics about how to do it , but i get stuck of state and props this is one of the classes:
import React, { Component } from "react";
import { useHistory } from "react-router-dom";
class Description extends Component {
render() {
const handleSubmit = () => {
this.props.completeTask(this.props.selectedTask, this.state);
};
const history = useHistory();
return (
<>
<p>Completer donnees incident</p>
<label for="description">Description:</label>
<input
type="text"
id="description"
name="description"
onChange={(e) => this.setState({ emetteur: e.target.value })}
/>
<br />
<form action="/">
<button type="button" className="btn btn-primary" onClick={handleSubmit}>
Complete
</button>
<button
type="button"
className="btn btn-primary"
onClick={history.goBack()}
>
Back
</button>
</form>
</>
);
}
}
export default Description;
how can I use this in function :
const handleSubmit = () => {
this.props.completeTask(this.props.selectedTask, this.state);