jeremybarbet / react-native-portalize

The simplest way to render anything on top of the rest.
MIT License
335 stars 22 forks source link

Why index in the Portal key? #25

Open ironchestgames opened 2 years ago

ironchestgames commented 2 years ago

Hi, we were having some problems in our app with components being unmounted in an unpredictable way. We traced it back to this line below.

Let's say a portal was unmounted, doesn't having the index in the key ensures that those Portals in the list after the unmounted one rerenders because of the new key, but the ones in the beginning of the list will not? (since their key will be the same due to being at the same index as before)

react-native-portalize-jibberishkey000-0
react-native-portalize-jibberishkey111-1
react-native-portalize-jibberishkey222-2

unmount react-native-portalize-jibberishkey111-1

react-native-portalize-jibberishkey000-0 <- same key
react-native-portalize-jibberishkey222-1 <- new key

https://github.com/jeremybarbet/react-native-portalize/blob/cf09c488b58b73c406571e9203f07cfc4af59de8/src/Manager.tsx#L40