I've noticed some people writing a "renderSomething" method that returns some jsx. This renderSomething method is called within the actual render() of a react component.
Something like this simple example:
renderTab(title, isVisible) {
return (
<div>
... some html/jsx that uses title and isVisible
</div>
);
}
render() {
return (
<div>
{this.renderTab('Tab 1', true)}
{this.renderTab('Tab 2', true)}
{this.renderTab('Tab 3', false)}
</div>
);
}
Normally I would extract that renderSomething into it's own component:
render() {
return (
<div>
<Tab title='Tab 1' isVisible=true />
<Tab title='Tab 2' isVisible=true />
<Tab title='Tab 3' isVisible=false />
</div>
);
}
I think extracting it into it's own component makes it easier to test and goes well with the react's approach to components but I keep seeing this "renderSomething" pattern from multiple people. I am curious if there is a preferred best practices approach. Are either OK? Which one is considered best practice?