Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Components (2018) Managing State and Data Flow Adding Items to State

Umidjon Khaitov
Umidjon Khaitov
8,884 Points

Text field is not getting cleared up after Submit event

I think here is the main part which should clear up input field. Other than that I'm kinda lost, don't know how to find this bug. I tried to console log(this.setState({ value: ''})) as a last statement in this function, it says undefined.

handleSubmit = (e) => {
    e.preventDefault();
    this.props.addPlayer(this.state.value);
    this.setState({ value: ''});
  }
Dom Ss
Dom Ss
4,339 Points

Try console log the value like this in the render method.

render () {
        console.log(this.state.value, 'value')
        return (`

Also double-check your :

state = {
        value: ''
    };

I saw some answers were people changed

state = {
        value: ''
    };

to

state: {
        value: ''
    };

and it worked. O.o

Make sure there are NO TYPOS in any of the "value" keyword. ;)

1 Answer

Edith Allison
Edith Allison
2,946 Points

Did you follow the code at around 7:15 minutes of the video? You need to change

    handleSubmit = (e) => {
        e.preventDefault();
        this.props.addPlayer(this.state.value); 
    }

to

    handleSubmit = (e) => {
        e.preventDefault();
        this.props.addPlayer(this.state.value); 
        this.setState({
            value: ''
        });
    }
Umidjon Khaitov
Umidjon Khaitov
8,884 Points

yeah you were right! thank you!