Take the following example code:
class Something extends Component {
render() {
return (
<SomeProvider
render={providedProps => (
<SomeChild {...providedProps}/>
)}
/>
)
}
}
Every React render props article uses this pattern as an example, but it's generally bad practice to define functions inline. Is this an exception to that rule?
Is there any benefit to defining the function outside of render?
class Something extends Component {
renderSomeChild = providedProps => (
<SomeChild {...providedProps}/>
)
render() {
return (
<SomeProvider
render={this.renderSomeChild}
/>
)
}
}
My suspicion was correct that the renderProps function should not be re-declared within the render function - or else it will force re-renders. I confirmed this Why Did You Render?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With