I am working on an existing React Tab container, which handles tab clicking on its own, automatically setting its own “active tab index” state.
I want to allow the parent container to programmatically tell the tab container to “go to” a particular tab index.
Is it better to expose an imperative gotoTab()
API via useImperativeHandle
, or should I move the activeTab
state to a prop and rely on the parent setting the right index – presumably the parent would also need some kind of onTabWillChange
callback from the tab container so that it can feed the new index back as a prop?