Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared/Common api location ? #69

Open
ChambreNoire opened this issue May 11, 2022 · 5 comments
Open

Shared/Common api location ? #69

ChambreNoire opened this issue May 11, 2022 · 5 comments

Comments

@ChambreNoire
Copy link

Hello.
Quick question: Where would you put shared react-query wrappers? Say one were to have a modal dialog that is used by multiple features (and therefore lives in /components) and that is responsible for loading something from a server endpoint...
Cheers

@Odas0R
Copy link

Odas0R commented Aug 15, 2022

I would put it under /hooks of the specific feature.

@CodeNameGrant
Copy link

@ChambreNoire

Like @Odas0R said, the /hooks directory would work.

I put them in a /api directory to separate api specific hooks from other hooks. Also its adds a bit of consistency, so any react-query wrappers are found in the /api directory regardless of whether its in a feature or not.

@Odas0R
Copy link

Odas0R commented Oct 26, 2022

Yeah, I agree, @CodeNameGrant. I guess I may have misunderstood the question since I've been doing exactly how you said for a couple of months 😆.

@BigSamu
Copy link

BigSamu commented Jul 12, 2024

@CodeNameGrant, @Odas0R,

Can you give a concrete example with this?

What if you have a feature called products where you allocate API custom hooks in the API folder, and then in another feature called requests, you need the APIs from products to create a component there? Let's say a RequestForm.tsx that has as input a combo box field which requires a list of all products in the backend.

In this case, you will need to grab the custom hook useProducts from feature products and use it inside RequestForm.tsx. However, in this case, you will not be following the structure defined by @alan2207 as it is detailed in project-structure.md. There is no isolation between features, because request feature is using logic from products feature.

@BigSamu
Copy link

BigSamu commented Jul 30, 2024

@CodeNameGrant, @Odas0R,

Can you give a concrete example with this?

What if you have a feature called products where you allocate API custom hooks in the API folder, and then in another feature called requests, you need the APIs from products to create a component there? Let's say a RequestForm.tsx that has as input a combo box field which requires a list of all products in the backend.

In this case, you will need to grab the custom hook useProducts from feature products and use it inside RequestForm.tsx. However, in this case, you will not be following the structure defined by @alan2207 as it is detailed in project-structure.md. There is no isolation between features, because request feature is using logic from products feature.

@alan2207 any suggestion on this? I would appreciate your comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants