I have a component Marker, which I don't want to rerender unless really needed.
So it's wrapped in a memo hook, but since one of the props is an anonymous function, then the Marker still rerenders every time it's parent rerenders.
Now, this would have a simple solution of just wrapping the passed in function prop in useCallback hook, but since the function also takes a parameter, then I'm bit stuck in finding a nice solution. Memoizing the passed in function in a parent component with useMemo also will not work because of that parameter.
const Map = () => {
...
...
return(
{markers.map(marker => {
<Marker {...props} onPress={() => selectMarker(marker.id)}
})
)
}
const Marker = (...props, onPress) => {
... memoized function that at some point calls onPress()
}