I have a moderately complex React application, made using create-react-app
and thus using react-scripts
to e.g. launch the development server.
I want to develop a new React component: a moderately complex input control that will let the user enter structured data. It is going to have buttons to add new entries in lists, dropdowns to pick from available options, etc.
This component isn't necessarily going to appear on the front page of my main React application; it is probably going to take a few clicks to get the application to show it in a state where I can usefully play with it. So I want to be able to get the component into the browser without the rest of the application, and feed it some hand-coded test data. Basically an interactive version of a unit test, so I can look at just that component and decide if I am happy with what it looks like and what it does when I poke it.
I would like to be able to use the React development server to work just on my component, without the rest of the main application being displayed. I want to create a file that says to render my component with certain props, and then show that in the browser with the development server's live-reload set up, so that I can e.g. see what I am doing while writing the CSS.
How do I make this work? It looks like React thinks in terms of there being one web page with one "application" per package.json
, and there's no way I can find to say e.g. npm run start -- --page=my-component-demo.html
Do I need to make my project into a monorepo with several interlinked Node modules, and put this component in its own create-react-app
app that renders a demo page? Do I need to add React routing to my main application, and define some routes that instead of the real application UI render just the demo page, and hope that having the whole application involved doesn't slow down the dev server's rebuilds too much?