oblador / react-native-collapsible

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

slowness #471

Open arshiya-adafsa opened 1 year ago

arshiya-adafsa commented 1 year ago

very slow when there is more than 20 items

kashmiry commented 2 months ago

I was facing the same issue. I made a few improvements to my implementation and was able to enhance performance.

1- I made sure I am passing components correctly I am utilizing touchableComponent prop. I was passing it like this:

<Accordion
    touchableComponent={(props) => <myTouchable {...props}>}
    {...}
/>

corrected it by passing it directly to avoid re-renders

<Accordion
    touchableComponent={myTouchable}
    {...}
/>

2- I used useMemo for renderSectionTitle, renderHeader, renderConten to also avoid re-render when state is changed.

const SliderHeader = React.memo(({ item }) => {
    ...
});
<Accordion
    renderHeader={(item) => <SliderHeader item={item} />}
    {...}
/>

Review your code throughly and make sure your utilizing React Memo when its needed.