0

I used to make bunch of buttons through for-looping. title[] has a lot of values.

export const renderButtons1 = (numOfBtns,title,navigate) => {
    const views1 = [];  
    for ( var i = 0; i < numOfBtns; i++) {
            views1.push(
            <Button 
                 key={i}         
                 title = {title[i]}
                 onPress={() => navigate('List', { 
                     Title : title[i]
                })}
                 color="#841584"
             />);


      }

    return views1;
}

in EventListscreen, Title: title[i] does not work, i value is not recognized

the one I want to ask is when I click first button, index 0 will be retrieved.

I thought I can use button key, but it is not fixed value - when I click first button at first and at second time, it is different..

user7503333
  • 33
  • 1
  • 9

1 Answers1

0

I found the way, you guys need to make the function for making buttons

so it looks like this

export const makingbutton = (i,ttl,navigate) => {
  return   <Button 
             key={i}         
             title = {ttl[i]}
             onPress={() => navigate('List', { 
                 Title : title[i]
            })}
             color="#841584"
         />


}

export const renderButtons1 = (numOfBtns,title,navigate) => {
const views1 = [];  
for ( var i = 0; i < numOfBtns; i++) {
        views1.push(
          makingbutton(i,title,navigate)
      );


  }

return views1;
}
user7503333
  • 33
  • 1
  • 9