I'm writing this app using React and I was trying to package it up in NPM to use it in a different project.
I have as my index.js
entrypoint something like this:
import { MyReactComponent } from './mypackage';
export { MyReactComponent } // for 3rd party packages who use this package
// to display the component when I'm running this package to test out changes
ReactDOM.render(
<MyReactComponent />,
document.getElementById('react')
)
If I want to use my package in another library, I should delete the ReactDOM.render()
part because that's causing problems. But I'd still like the render part when I'm testing changes "standalone".
Is there something I can do? I think I want a setup similar to Python's if __name__ == "__main__":
paradigm. I'm also willing to switch to the React way of doing it, if there is one.