Curious about building your own React Native Component Module library but don’t know where to start? Well this resource will get you started.
- Create new Component Module Folder your custom modules folder in your project. (Create one if it does not exist (e.g. customModules)).
- Using terminal, cd to the new Component Module folder you just created.
- Init the npm by typing: npm init. Answer all the questions.
- Create an index.js file. This file is the entry point for your module. Create a normal React Native Module here. (Don’t forget to export as normal) (E.g. export default function FunctionName ())
- Add parent dependencies for the module by adding “peerDependencies” in the package.json. Example: “react” : “^17.0.1”, “react-native”: “^0.64.3”.
- Import component using the path to the customModule.
- After testing, follow next post for preparing for NPM uploading.