0

I use react-native-tab-view

if I am on a new page I want to get displayed the index of the page or anything else.

I have a solution but its slow, I set the index as a prop but I get the console log result after 1 sec. thats bad. is there any other solution ?

code:

const SearchMain = ({}: ISearchMain) => {
  const { t } = useTranslation();
  const [index, setIndex] = React.useState(0);
  const [routes] = React.useState([
    { key: 'products', title: 'Produkte'},
    { key: 'users', title: 'Personen' },
  ]);

  const renderScene = ({ route }: { route: { key: string; title: string; } }) => {
    switch (route.key) {
      case 'products':
        return <Products index={index} />;
      case 'users':
        return <Users index={index} />;
        return null;
    }
  }
  return (
    <TabView
      lazy
      navigationState={{ index, routes }}
      renderScene={renderScene}
      onIndexChange={setIndex}
      keyboardDismissMode='auto'
      initialLayout={initialLayout}
      renderTabBar={renderTabBar}
    />
  );
}
universe11
  • 703
  • 1
  • 11
  • 35

0 Answers0