Reputation: 39
Is it possible to create a method that contains passing props that will be use for multiple components.
passingPropsMethod(){
return(
something={this.state.something}
something2={this.state.something2}
)
}
Tried this code but has "Unreachable code detected".
What would be the best approach to achieve this?
Upvotes: 1
Views: 55
Reputation: 504
You should return an object from the function instead:
passingPropsMethod() {
return {
something: this.state.something,
something2: this.state.something2
}
}
And pass it to your component like this:
<Component {...passsingPropsMethod()} />
or
const props = passsingPropsMethod()
<Component {...props} />
Upvotes: 2