Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.