Manage State Locally First(It's work but not pass any case)

Manage State Locally First(It's work but not pass any case)
0

#1

//This code working but not pass the test can you tell me where is the problem?

class DisplayMessages extends React.Component {
constructor(props) {
super(props);
this.state = {
input: ‘’,
messages: []
}

            this.handleChange = this.handleChange.bind(this);
            this.submitMessage = this.submitMessage.bind(this);
        }
        // add handleChange() and submitMessage() methods here
        handleChange(e){
            this.setState(
                {
                    input: e.target.value,
                }
            );                
        }

        submitMessage(e){                
            e.preventDefault();                                
            let msgInput = this.state.input                
            console.log(this.state.messages);
            this.setState(
                {
                    input: '',
                    messages: [...this.state.messages , msgInput]                        
                }
            );                
        }

        render() {

            let arrayValue = this.state.messages;
            arrayValue = arrayValue.map((item) => {
                return(
                    <li key={item}>{item}</li>
                );
            });

            return (
            <div>
                <h2>Type in a new Message:</h2>
                { /* render an input, button, and ul here */ }
                    <form onSubmit={this.submitMessage}>
                        <input type="text" value={this.state.input} onChange={this.handleChange} />
                        <input type="submit" value="Save" />
                    </form>
                    <ul>{arrayValue}</ul>                        
                { /* change code above this line */ }
            </div>
            );
        }
        };

#2

Can you make sure your code is fully formatted and add a link to the exercise?


#3

Thanks @shimphillip, it’s fixed. Actually problem in submit button. I am using input type button but he needs simple button.