r/reactnative • u/mzakria__real • Sep 25 '26
FYI Made a small hook for React Native layouts that change with screen size
I kept writing the same code to switch between one and two columns when the phone rotates or the app runs on a tablet, so I turned it into a small library.
const { select } = useResponsive();
const columns = select({ xs: 1, md: 2, xl: 3 });You get named breakpoints (xs to xxl), wp/hp, a font size helper and a few scale functions, and everything updates when you rotate. Works with Expo and on web too.
The screenshots are from the example app on an iPhone 16, portrait vs landscape.
npm: https://www.npmjs.com/package/react-native-responsive-hook
GitHub: https://github.com/mz-real/react-native-responsive-hook
Longer write-up with examples: https://medium.com/@mz-real/creating-responsive-uis-in-react-native-made-easy-with-react-native-responsive-hook-35fa5649cd5f
I'm working on a 2.0, so feedback is welcome.
1
u/jwrsk Sep 26 '26
For the real time measurements, do you take the app window or the device screen?
1
u/Cryo0007 Sep 26 '26
I guess this will make it re render screen a lot
2
u/ProgramerLife Sep 26 '26
Nice!
1
u/itballer Sep 27 '26
Epic stuff mate!