-
Notifications
You must be signed in to change notification settings - Fork 50.5k
Closed
Description
Just read about getDerivedStateFromProps and am concerned the new api won't be flexible enough to cover some common use cases.
For instance, I have a scrolling tabs component. Whenever the selectedTabId prop changes I use browser apis to scroll that tab into view. What would be the best way to accomplish this without componentWillReceiveProps?
Currently code is something like this:
class Tabs extends React.Component {
render() {
return (
<div className="tabs-container">
{this.props.tabs.map(tab => (
<div className="tab" key={tab.id} id={tab.id}>
{tab.title}
</div>
))}
</div>
);
}
componentWillReceiveProps(nextProps) {
if (nextProps.selectedTabId !== this.props.selectedTabId) {
document.querySelector(`#${nextProps.selectedTabId}`).scrollIntoView();
}
}
}Metadata
Metadata
Assignees
Labels
No labels