oblador / react-native-collapsible

Animated collapsible component for React Native, good for accordions, toggles etc
MIT License
2.43k stars 453 forks source link

Can i pass props into renderContent? #366

Open Jinentonik opened 4 years ago

Jinentonik commented 4 years ago

Hi,

I need to create a button inside renderContent. When the button is clicked, it will update the server and receive new list from server . So, i will need to pass my list data into renderContent.

Can anyone teach me how to pass props inside renderContent?

This is my original code and this works fine.

 <Accordion
                    activeSections={activeSections}
                    sections={orderData}
                    renderHeader={renderHeader}
                    renderContent={renderContent}
                    onChange={setSections}
                    expandMultiple= {expandMultiple}
                    sectionContainerStyle={styles.accordionSection}
                />

But i cannot find a way to pass 'setOrderData' into renderContent. This is what i have tried and it does not work:

 <Accordion
                    activeSections={activeSections}
                    sections={orderData}
                    renderHeader={renderHeader}
                    renderContent={(section, idx, isActive )=>{
                      return(
                        <RenderContent section = {section} isActive={isActive}/>
                      )
                    }}
                    onChange={setSections}
                    expandMultiple= {expandMultiple}
                    sectionContainerStyle={styles.accordionSection}
                />
mertavcioglu commented 11 months ago
<Accordion
   renderContent={() => renderContent(bgColor, fertilizers)}
/>

const renderContent = (bgColor, fertilizers) => {
  return (
    <View style={[styles.viewContainerStyle, { backgroundColor: bgColor }]}>
      {renderFertilizersForMonth(fertilizers)}
    </View>
  );
};

This is the way I do it.