alan2207 / bulletproof-react

🛡️ ⚛️ A simple, scalable, and powerful architecture for building production ready React applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Contexts folder at feature level

ruiaraujo012 opened this issue · comments

Shouldn't we be "able" to have contexts for specific features?
Like:

src/features/awesome-feature
|
+-- api         # exported API request declarations and api hooks related to a specific feature
|
+-- assets      # assets folder can contain all the static files for a specific feature
|
+-- components   # components scoped to a specific feature
|
+-- hooks       # hooks scoped to a specific feature
|
+-- routes      # route components for a specific feature pages
|
+-- stores      # state stores for a specific feature
|
+-- types       # typescript types for TS specific feature domain
|
+-- contexts       # react context to this specific feature <-------------- THIS
|
+-- utils       # utility functions for a specific feature
|
+-- index.ts    # entry point for the feature, it should serve as the public API of the given feature and exports everything that should be used outside the feature

We could have a context folder at the root too.

Hi @ruiaraujo012 , of course you can, that's the desired approach, I just didn't add it in the document, but it can be anything, it's important to keep it as close as possible to the feature it belongs to.

One thing worth mentioning: hooks consuming the same context should be co-located and not separated in the hooks folder. You can structure it however you find more intuitive, but I would suggest you keep your context-related hooks close to the context. For example:AwesomeFeatureContext and useAwesomeFeature should probably be in the same file.

Thanks for your reply.

Sure, the context related hooks should be at least in the context folder if not in the context file.

No, if you decide on that path, it should probably be in the same file, unless your file grows huge, in that case you should split it.

Yes, that's what I was referring to

Oh cool, looks like I misread your message :)