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.
      1. dateutils.js
      2. stringutils.js
      3. 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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -