Globally replace a component in react native

63 views Asked by At

I have a React Native app with a fairly large codebase. I recently received a new requirement that requires me to add debounce functionality to all the buttons in the app. If I replace them with a custom component, it will result in a significant number of file changes. I tried configuring Babel's 'module-resolver', but it doesn't seem to be helping. Is there a better way to achieve this, or should I manually replace it everywhere?

1

There are 1 answers

0
Ons belkhouja On

If you're using a shared component for your button or pressable it could be easily done ( that's the importance of having shared components, so that you can do changes globally in an effective way ) if not, there's a turnaround, you patch the library that you're using your buttons from ( react-native if you're using the common react native button ) and you add the debounce to the library so it will change globally and in the future too. For patching you can use patch-package

https://www.npmjs.com/package/patch-package

By patching I mean updating the package in node modules.