I'm trying to pass a remove function into the map with a parameter, but it's like I'm not using my function. What would be the correct way to call ''remove(i)'' inside InputTime in onRemove?
Component
render() {
const {remove} = this.props;
return(
<>
<InputTime
onRemove={() => remove(i)}
{...this.props}
/>
</>
)
}
}
// another class
handlerRemove(){
...
}
return(
<Component remove={() => this.handlerRemove()} />
)
Here you go with a solution
render() {
const {remove} = this.props;
return(
<>
<InputTime
time={hour}
onRemove={() => remove(i)}
{...this.props}
/>
</>
)
}
}
As you have done the destructing using const {values, remove} = this.props;, then you don't need to add this for prop function.
Current code onRemove={() => this.remove(i)}
Change you code to onRemove={() => remove(i)}
As the user change the code a bit, based on that the solution
Component
render() {
const {remove} = this.props;
const arg = "test";
return(
<>
<InputTime
onRemove={() => remove(arg)}
{...this.props}
/>
</>
)
}
}
// another class
handlerRemove(passedArg){
console.log("passedArg", passedArg);
}
return(
<Component remove={this.handlerRemove} />
)