How to use the npm library in your react app In ReactJS
Step 1: Create React app:
npx create-react-app my-app
cd my-app
Step 2: Install Your Library
Install your npm library in your React app.
npm install my-react-library
you can find your react library in the node_modules after installation.
Step 3: Use your Library Component:
Javascript
// my-app/src/App.js import React from 'react' ; import Button from 'react-button-library' ; function App() { return ( <div className= "App" > <Button /> </div> ); } export default App; |
Step 10: Run Your React App:
npm start
Output:
How to create an npm library from React Components ?
Creating an npm library containing React Components is very simple. In this tutorial, we’ll create a library containing a button component that changes color when clicked. Then we’ll demonstrate how to consume this library in a separate React application.