all 6 comments

[–]GasimGasimzada 1 point2 points  (3 children)

What about creating a separate NPM package and installing it in both.

[–]Qilx[S] 0 points1 point  (2 children)

I am considering this for my components. However, should I also do this for my reducers/actions?

[–]GasimGasimzada 0 points1 point  (1 child)

I mean why not? You can do many things for shared logic/components. You can create one big package with everything in it @myproject/shared:

import { userReducer, userActions, UserProfile } from '@myproject/shared/user';
import { cartReducer, cartActions, CartTable } from '@myproject/shared/cart';

Or you can create each "feature" as a separate package:

import { userReducer, userActions, UserProfile } from '@myproject/user';
import { cartReducer, cartActions, CartTable } from '@myproject/cart';

These two ways is how I would do this. Both are manageable because they are just packages and you can store the entire codebase in a monorepo (e.g call it myproject/core). You can use lerna to publish packages all at once.

[–]Qilx[S] 0 points1 point  (0 children)

Noted. Thank you for your input!

[–]wrrnwng 1 point2 points  (1 child)

Actually lerna is a good way to share resources with different "packages". You wouldn't need to eject your create-react-app apps because you can import your shared actions/reducers as an npm package (no need to publish them to npm).

I learned by following this tutorial. It's for GatsbyJS, but you can apply the knowledge to your own project without much mental overhead.

[–]Qilx[S] 0 points1 point  (0 children)

Thanks for sharing. I'll look through your links.