How do I change a Component React to a React Hooks function?

Asked

Viewed 27 times

0

I want to take this whole Component and turn it into a hook with functions

export default class App extends Component {
    constructor(props) {
        super(props); 
        this.state = {
            selectedStartDate: null, 
            selectedEndDate: null,
        };
        this.onDateChange = this.onDateChange.bind(this);
    }
    onDateChange(date, type){
        if (type === 'END_DATE') {
            this.setState({ 
                selectedEndDate: date,
            });
        } 
        else 
        { 
            this.setState({
                selectedStartDate: date, 
                selectedEndDate: null,
            });
        }
    }
    render() {
        const { selectedStartDate, selectedEndDate } = this.state;  
        const startDate  =  selectedStartDate ? selectedStartDate.toString() : '';
        const endDate = selectedEndDate ? selectedEndDate.toString() : '';
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.