Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
How to select First item in FlatList as default one?

I'm trying to use Flatlist like Sidebar, but it intializes only after clicking on it, Is there any way by which I can make first flatlist item as default one. In other words onclick work should happen before page load like in lifecycleHooks Also suggest me If there is any way to create sidebar dynamically instead of using Flatlist

<FlatList
  data={Object.keys(this.state.groups)}
  renderItem ={({ item, index }) => 
  (
    <TouchableOpacity
      onPress={() => { this.showDetails(item),this.setState({itemIndex:index}) }}
      // onPress={() => alert(item)}
    >
    {console.log(index,"index of cards",Object.keys(this.state.groups),"item index")}  
    <View style={{width: 280, height:54 , flexDirection:"row",alignItems:"center",backgroundColor: (this.state.itemIndex === index) ? "#74C947" : "#F6F6F6"}}>
    {/* Use ExcludeIcon.svg  for stop symbol*/}
    {(this.state.itemIndex === index) ? 
    <Image source={require("../../../assets/images/WhiteTick.svg")} style={{width:16,height:11,marginLeft:15,marginRight:9}}/>            
    : 
    <Image source={require("../../../assets/images/GreenTick.svg")} style={{width:16,height:11,marginLeft:15,marginRight:9}}/>
    } 
    <Text style={{
      fontStyle:"normal",
      fontWeight:"500",
      fontSize: 16,              
      color: (this.state.itemIndex === index) ? "#FFFFFF" : "#333333",
      textTransform:"capitalize"
    }}>
      {item}
    </Text>
    </View>
  </TouchableOpacity>
  )
}
  keyExtractor={item => item}
 />

Before On click

After On Click

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try this way

 state = {
   itemIndex: 0
 };

componentDidMount(){
  this.showDetails(this.state.itemIndex);
}
about 4 years ago · Juan Pablo Isaza Report

0

You can keep default value of itemIndex to 0 which selects the first element.

  constructor(props) {
    super(props);
    this.state = {itemIndex : 0};
  }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!