I have a react component that I want to publish to npm and I was hoping someone can explain a few things to help me get started with it. I have published node.js packages on npm in the past, but this is my first react package and I can't get it to work.
This is a small example of what I am planning to achieve:
My package label-wrapper:
import React, { useState, useEffect, useRef, useCallback } from 'react';
export default function ({ label }) {
return <div className="label-wrapper">{label}</div>
};
Other people that want to use my package:
import React from 'react';
import LabelWrapper from 'label-wrapper';
export default function () {
return <div><LabelWrapper label="Hello World" /></div>
}
Do I use
create-react-app
for this? Or do I installreact
andreact-dom
manually? Because I want to make it very small that can be imported to other projects. Its kinda likereact-router-dom
ormaterial-ui
but very, very smaller.If I use
create-react-app
do I need to build (react-scripts build
) also? This is where I am most confused, becausecreate-react-app
is for building single page apps and it carries a lot of extras that I don't need.
If you have a link with a thorough guide for this, it would really help.