I have the following component. It works great to create the initial set of tabs.
import * as React from 'react';
import { TabBar, TabView } from 'react-native-tab-view';
import { CollectionList } from './components';
const renderTabBar = (props) => <TabBar {...props} scrollEnabled />;
const RarityTabs = ({ collectionId, rarities }) => {
const rarityRoutes = rarities.map((rarity) => ({
key: rarity.variant,
title: rarity.quality,
rarity,
}));
const [index, setIndex] = React.useState(0);
const [routes, setRoutes] = React.useState(rarityRoutes);
return (
<TabView
lazy
navigationState={{ index, routes }}
renderScene={({ route }) => (
<CollectionList collectionId={collectionId} selectedRarity={route.rarity} />
)}
renderTabBar={renderTabBar}
onIndexChange={setIndex}
/>
);
};
export default RarityTabs;
However, rarities
can change and I'd like to make the tab route creation respond accordingly.
When I try useEffect
to to fire setRoutes
it locks up the app.
How can do you create a way for routes to be dynamic? Thanks!