Facebook
From Artur Grabowski, 1 Year ago, written in JavaScript.
This paste is a reply to Type of web from Artur Grabowski - go back
Embed
Viewing differences between Type of web and Re: Type of web
import * as React from 'react';

class MyFirstForm extends React.Component {
        state = {
                name: '',
                color: 'blue',
                message: '',
                isChecked: true,
                choice: ""
        };

        handleChange(e, val) {

                switch (val) {
                        case "name": {
                                this.setState({
                                        name: e.target.value
                                });
                                break;
                        }
                        case "color": {
                                this.setState({
                                        color: e.target.value
                                });
                                break;
                        }
                        case "message": {
                                this.setState({
                                        message: e.target.value
                                });
                                break;
                        }
                        case "isChecked": {
                                this.setState({
                                        isChecked: e.target.checked
                                });
                                break;
                        }
                        default:
                                console.log("cos nie dziala w switchu");
                }
        }


        handleNameChange = (e) => {
                this.setState({
                        name: e.target.value
                });
        };
        handleColorChange = (e) => {
                this.setState({
                        color: e.target.value
                });
        };
        handleMessageChange = (e) => {
                this.setState({
                        message: e.target.value
                });
        };
        handleCheckboxChange = (e) => {
                this.setState({
                        isChecked: e.target.checked
                });
        };

}
        

        render() {
                return (
                        

                                 this.handleChange(e, "name")}/>
                                 this.handleChange(e, "color")}>
                                        Czerwony
                                        Niebieski
                                        Zielony
                                
                                 this.handleChange(e, "message")}/>
                                
                        

                );
        }
}

export default MyFirstForm;