javascript - React structure for own utils files -
is there best practice in structure react app? sometimes, need move universal functions separate files. but, where? it's not node_module.
- .gitignore
- .git
- package.json
- node_modules
- src
- components
- views
- reducers
- actions
- utils ← utils folder.
- dateutils.js
- stringutils.js
- numberutils.js
the way create base react component contain utils. react files child of component.
class mybasecomponent extends react.component { dateutilsmethod() { ... } stringutilsmethod(mystring) { ... } } class mainpageview extends mybasecomponent { ... }
what best solution?
i think on right track, though arguable.
1 thing missing in opinion index file in utils folder exposes each util file via export
.
example:
//utils/index.js: export { default dateutils} './dateutils'; export { default stringutils} './stringutils'; export { default numberutils} './numberutils';
and import them other files so:
import { dateutils, numberutils} '../utils ';
or import alias:
import * utils '../utils ';
Comments
Post a Comment