Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Redux app structure multiple roles

I'm planning to do a SPA web app using react redux, I'm stuck at figuring out the right architect for the front end.

So the app can have user to bid product, and admin to approve or manage product. How would the app structure like?

actions
- admin
- user
reducers
- admin
- user
containers
- admin
- user
components
route.js //load admin or user
userStore.js
adminStore.js

Is above structure make sense? route.js will detect role and load relevant route, then in each redux related folder like actions, reducers, store have to have 2 version.

like image 754
Jenny Mok Avatar asked Apr 19 '26 21:04

Jenny Mok


1 Answers

If you are using Webpack you can try multiple src and entry like that:

src-admin
 - actions
 - reducers
 - containers
 - components
 - ...
 - adminRoute.js
 - admin.js
src-user
 - actions
 - reducers
 - containers
 - components
 - ...
 - userRoute.js
 - user.js
webpack.config.js

and in webpack.config.js:

entry: {
  app: ['./src-user/user.js', '.src-admin/admin.js'],
  vendors: ['react']
}
like image 140
Emad Emami Avatar answered Apr 22 '26 11:04

Emad Emami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!