jaredh159 / tailwind-react-native-classnames

simple, expressive API for tailwindcss + react-native
2.08k stars 84 forks source link

useDeviceContext triggers re render too often #246

Closed EliasGit117 closed 1 year ago

EliasGit117 commented 1 year ago

Because of changing app's size it triggers re render on each pixel size that has been changed. This sounds not really performant, can be something done with it?

jaredh159 commented 1 year ago

are you targeting RN Web? in native environments (which is all this library aims to support), resize don't happen very often, usually only on orientation change, so it's not much of an issue. it's not like on the web where the user might grab the corner of a screen and drag to resize.

EliasGit117 commented 1 year ago

@jaredh159 okay, but in case if use it on web too, is there a way to fix it?

jaredh159 commented 1 year ago

not something simple that's readily available in the library. you could probably add some of your own code to debounce window resize events and then possibly call into the device context somehow to re-render less frequently, but you'd have to implement that yourself, and i don't think it would be trivial. sorry. :/ once again, it's just not the use case this library is targeting, so we don't have a good answer built-in.

EliasGit117 commented 1 year ago

Well, unistyles added debounce system.

https://github.com/jpudysz/react-native-unistyles/commit/b015d7b41aa01aecbbdd8041f7701d309b1436b1

jaredh159 commented 1 year ago

cool! maybe you could use that as an inspiration for building your own debounce wrapper for twrnc. until we change to also support RN Web, it's not something we'll be adding to the library itself. 👍