Questions about the solution


#1

Please help me understand as I am new to React and can’t grasp the pattern just yet.

I have 2 questions:

  1. On parent.js file, changeName function is defined like this:
changeName(newName) {
    this.setState({
      name: newName
    })
  }

My question is, what does the parameter “newName” means and where does it come from?

  1. Also on Parent.js file’s render:
  render() {
    return <Child name={this.state.name} onChange={this.changeName}/>
  }

Why does the attribute “onChange” equal to {this.changeName} even if in the Child.js file, it does not call the changeName, instead it calls the handleChange(e) method in the tag.

I cannot visualize the pattern just yet, please help me understand. Thank you.

Here is the link : https://www.codecademy.com/courses/react-102/lessons/child-updates-parents-state/exercises/automatic-binding?action=resume_content_item


#2

Somebody help please


#3
  1. New name is the import to the function of changeName.
    changeName is a function whose job is to change the state of ‘name’ to a new value which is newName.
  2. The reason onChange equals to {this.changeName} is because we want to pass the function onChange as a prop to the ‘Child’ component

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.