Share endpoints or queries/mutation between workspaces in a monorepo

Viewed 22

I have a monorepo with 2 different dashboards in 2 workspaces. I'm using rtk query for adding/fetching data and it has been very helpful.

Some of the APIs used to add/fetch data are common between these two dashboards. Some forms/tables are common too.

So I'm thinking of adding an other workspace that exports these common components(which import the mutation/query hooks provided by rtk-query) and also queries and mutations so that I don't have to duplicate and for any changes, I'll have to change in just one place. The backend API baseUrl is same in both the dashboards.

I don't know how I would do this because the store is created individually in each dashboard.

I'm thinking I'll create an apiSlice(created using createApi) containing the common APIs as endpoints in the common workspace and somehow merge this apiSlice into each dashboard's apiSlice.

And the components in this common workspace would import this common workspace's apiSlice.

This seems far-fetched, but it seems to be possible in react-query based on this github issue, if I understood the issue correctly.

So my question is how would I share the components and queries/mutations across workspaces in a monorepo.

0 Answers
Related