JavaScript React Components Managing State and Data Flow Adding Items to State

erkany
erkany
7,189 Points

How name argument passing through App.js from AddPlayerForm class?

In AddPlayerForm class, handleAddPlayer function has an argument 'name' that pass this.state.value. Whatever the value of this.state.value in that time will be passed to addPlayer function and called.

handleSubmit = (e) => {
        e.preventDefault();
        this.props.addPlayer(this.state.value);
        this.setState({value: ''});
        console.log('Handle submit' + this.state.value);

    }

My question is how this.state.value has been passed to handleAddPlayer function in App.js? Is it because of reference issue in props?

<AddPlayerForm addPlayer={this.handleAddPlayer}/>
Brandon White
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

Hi erkany,

I’m a bit confused about what you’re asking. Are you wanting to know how to pass an argument into the handleAddPlayer method?

1 Answer

erkany
erkany
7,189 Points

Yes Brandon, that was a question but I watched the videos several times and I think I got it. Sometimes javascript confuses me with other programming languages especially for function expression.

Thank you.