I am using React native and on one of my screens I have a toggle component. The component has 2 options and clicking on them renders different data. I've noticed performance is not bad on ios but awful on Android and I want it to be good on both (obviously)
The props and state are not changing every time I toggle so it should just be able to render it super fast? the second screen is where I'm seeing more of an issue. but is essentially a fairly big array, rendering a list with lists inside each one.
I've tried using this: export const CachedPreviousGames = React.memo(PreviousGames)
where PreviousGames
is the component in question
However, when I toggle back and forth I see that the component console.logs are fired, I also see the console.logs inside the .map
functions are called. is this expected? I was hoping React.memo
would only re-render if the props changed?
Is there any other caching strategy I can do to fix this to make it more performant?
MORE DETAILS
so the two components are League
and Previous Games
where I'm basically mapping over data from my redux store in League
and in Previous Games
it takes a prop of games
and maps over that.
it's quite an expensive function, verified by the fact that when I replace the map with just a Text
string, the toggle appears to happen much faster. When I say props don't change I mean, exactly that. Previous Games
loads up with fresh data on app load but it never changes (until this happens again). i.e. every time I toggle, the props remain constant
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…