bulletproof-react icon indicating copy to clipboard operation
bulletproof-react copied to clipboard

Where must I put these files? [React, React Native]

Open gianllopez opened this issue 1 year ago โ€ข 1 comments

First of all, I want to thank you for the fascinating work you are doing, but I have the following situation:

In my React Native project, I have the following folder structure:

src
โ”œโ”€โ”€ assets
โ”‚ย ย  โ”œโ”€โ”€ fonts
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ *.ttf
โ”‚ย ย  โ””โ”€โ”€ icons
โ”‚ย ย      โ””โ”€โ”€ *.svg
โ”œโ”€โ”€ components
โ”‚ย ย  โ”œโ”€โ”€ *.tsx
โ”œโ”€โ”€ config
โ”‚ย ย  โ”œโ”€โ”€ constants.ts
โ”‚ย ย  โ””โ”€โ”€ theme
โ”‚ย ย      โ””โ”€โ”€ colors.js
โ”œโ”€โ”€ features
โ”‚ย ย  โ”œโ”€โ”€ malls
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ components
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ *.tsx
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ index.ts
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ screens
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ *.tsx
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ index.ts
โ”‚ย ย  โ””โ”€โ”€ users
โ”‚ย ย      โ”œโ”€โ”€ interfaces
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ *.ts
โ”‚ย ย      โ””โ”€โ”€ screens
โ”‚ย ย          โ”œโ”€โ”€ *.tsx
โ”‚ย ย          โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ lib
โ”‚ย ย  โ””โ”€โ”€ react-native-vector-icons
โ”‚ย ย      โ””โ”€โ”€ *.json
โ””โ”€โ”€ navigation
    โ”œโ”€โ”€ navigators
    โ”‚ย ย  โ”œโ”€โ”€ *.tsx
    โ””โ”€โ”€ types
        โ”œโ”€โ”€ *.ts

And I have several questions:

  1. Where can I place constants that will only be used within a specific feature?
  2. Where can I place groups of TypeScript enum that will only be used within a specific feature?
  3. Where can I place groups of TypeScript enum that are going to be used throughout the entire application?

Thank you in advance, I hope to receive a response as soon as possible.

Gian Lรณpez.

gianllopez avatar Mar 26 '24 03:03 gianllopez

Hey @gianllopez , thanks for the kind words!

I think you answered the questions yourself, if it's local to a feature, keep it there. If it's only used in one place, feel free to keep it in the same file where it's used, no need to add extra files just for that. If it's reused within the feature, moving it to features/my-feature/types.ts or feautres/my-feature/constants.ts might make sense.

As for the global enum, you can have a global types.ts file where you can put all global types, similar to https://github.com/alan2207/bulletproof-react/blob/master/src/types/index.ts .

alan2207 avatar Apr 09 '24 19:04 alan2207