How to pass multiple input fields between parent / child?


#1

I wonder ho to pass multiple inputs? In the coding exercise its always just 1 input field, but what if its multiple? The code below wouldn’t work for gulp. inputs…Thanks!!

 handleChange(e) {
   const name = e.target.value;
   this.props.onChange(name);
}

#2

Are you referring to multiple input fields using the same handler?

handleChange(e) {
   const name = e.target.value;
   this.props.onChange(name);
}

The above code captures the value of the input field. To let the function work with multiple fields, capture only the control, and not the value. That will give us a target node, which we can then identify to direct flow through one function or another.

const targetNode = e.target;
if (targetNode.className === "...") {
    this.props.funcName(targetNode.value);
} else
if ( ... } {

} else {

}

More of less. If the field has a placeholder attribute, that can be used instead of the class name.


#3

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