ptomasroos / react-native-scrollable-tab-view

Tabbed navigation that you can swipe between, each tab can have its own ScrollView and maintain its own scroll position between swipes. Pleasantly animated. Customizable tab bar
https://www.npmjs.com/package/react-native-scrollable-tab-view
6.93k stars 2.29k forks source link

Refresh the component on every tab change #1175

Open yogendrajs opened 2 years ago

yogendrajs commented 2 years ago

I want to know if there's a way to refresh the component on every tab change because componentDidMount doesn't re-invoke when we return to the rendered/previous tab (as it's already in the stack)

devoren commented 2 years ago

Try something like this:

`const [tabIndex, setTabIndex] = useState(0); const [isRefreshing, setIsRefreshing] = useState(false);

React.useEffect(() => { setIsRefreshing(true) after fetching data setIsRefreshing(false) }, [tabIndex]);

<ScrollableTabView ... onChangeTab={(value) => { setTabIndex(value.i); }} ...`