khevamann / rn-responsive-styles

Responsive styles for react-native and react-native-web
MIT License
40 stars 3 forks source link

Remove Undefined Listener Crash #4

Closed khevamann closed 2 years ago

khevamann commented 2 years ago

Fixed issue where sometimes listener was not being created so remove was throwing an error. We should only remove it when it exists

EthanHermsey commented 2 years ago

I was just about to open an issue for this :p When conditionally rendered components unmount, this pops up. Also when flexbox content changes to flex: 0 I get this. I've noticed it's only once though.. When the flex changes to something that's visible and back to 0, it doesn't give the error a second time.

Unfortunately with this fix it still give a 'Can't perform a React state update on an unmounted component' error, but that might be because I'm not using it as intended... I've got a hook useStyle where I call and return createResponsiveStyle(global,responsive) and in the component I call that hook, which gives me the {style, deviceSize}. Can you confirm this is correct or not? Should I call createResponsiveStyle on the component level instead?

khevamann commented 2 years ago

@EthanHermsey Yes, that is used correctly. The error you mentioned is technically just a warning. But usually means something is wrong elsewhere. Does it say the error is coming from this package? If so could you post a screenshot and maybe what hooks you are calling? Then I can look into it a bit.

EthanHermsey commented 2 years ago

It was indeed a Pressable component that gave the error, it had nothing to do with this package. I was trying to get more error information, but with the latest release I'm having trouble creating any errors, how inconvenient ;) It's a bit strange, because I'm also not getting the listener errors..

This is gold, works very well now. I've switched to the 1.1.0 now completely. I'm using it with rn-web without a problem, thanks so much!

khevamann commented 2 years ago

Awesome, have merged this PR. I think the issue only occurred when it was being used in multiple components on the same page. But didn't find an exact reproducible example