0

I need to pass the items.id into OnChangeTab I have use the tabs from the native-base library insted of index I want to send the dynamic id so that I can send the same id to my api

   <Tabs
            // locked={true}
            tabBarUnderlineStyle={{backgroundColor: '#E60000'}}
            onChangeTab={({i}) => this.handleClickCat(i)}
            renderTabBar={() => <ScrollableTab />}>
            {this.props.data &&
              this.props.data.map((items, index) => {
                return (
                  <Tab
                    heading={
                      <TabHeading>
                        <TouchableOpacity
                          onPress={() => this.setState({id: items.id})}>
                          <Text>{items.title}</Text>
                        </TouchableOpacity>
                      </TabHeading>
                    }
                   key={items.id}
                    tabStyle={{backgroundColor: '#1D1E1F'}}
                    // onChangeTab={() => this.handleClickCat()}
                    // activeTab={() => this.setState({id: items.id})}
                    // o={this.setState({id: items.id})}
                    activeTabStyle={{backgroundColor: '#1D1E1F'}}
                    textStyle={{color: '#9E9E9E'}}
                    activeTextStyle={{color: '#FFFFFF'}}>
                    <AllNewsScrolimage
                      navigation={this.props.navigation}
                      data={this.props.catdata}
                      id={items.id}
                    />
                  </Tab>
                );
              })}
          </Tabs>
Meisan Saba
  • 800
  • 2
  • 9
  • 25

1 Answers1

0

Here i is the index of tab so you can get item's id by doing like

handleClickCat(index){    
  const itemId = this.props.data[index].id; // Item id here
}

onChangeTab={({i}) => this.handleClickCat(i)}
Nooruddin Lakhani
  • 7,507
  • 2
  • 19
  • 39
  • i have doone this but i want to pass my **tems.id** insted of **i** in function **onchnageTab** `handleClickCat = (id) => { // alert(id); this.fetchDefaultdata(id); };` – Ritesh Rawal Nov 11 '20 at 16:04
  • NativeBase library default provides an index of Tab in its onChangeTab function. If you want items.id in onChangeTab instead of the index then you have to customize it accordingly. I can help you out with that but my answer will result you same as you required. You have your data set in props, so easily you can get an item's id from that – Nooruddin Lakhani Nov 12 '20 at 06:34
  • Hello i got the answer now thank you for your help as `onChangeTab={({ref}) => this.handleClickCat(ref.props.id)}` as **** – Ritesh Rawal Nov 12 '20 at 08:55
  • Yes, ref provides props that can access it. Greate :-) – Nooruddin Lakhani Nov 12 '20 at 08:59