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

Called injectEndpoints to override already-existing endpointName #3157

Closed
devoren opened this issue Feb 7, 2023 · 7 comments
Closed

Called injectEndpoints to override already-existing endpointName #3157

devoren opened this issue Feb 7, 2023 · 7 comments

Comments

@devoren
Copy link

devoren commented Feb 7, 2023

image

I'm using RTK Query with React Native and I've split the main API with injectEndpoints. I have this problem when i set overrideExisting false (DEV mode)

@phryneas
Copy link
Member

phryneas commented Feb 7, 2023

That is probably due to hot module reloading reloading the file when you apply changes to it.

You could try adding

overrideExisting: module.hot?.status() === "apply"

to the injectEndpoints call.

@devoren
Copy link
Author

devoren commented Feb 7, 2023

@phryneas Wow thanks for the quick response! The error is showing when I open the app for the first time and then if I change something the error is not shown.I am now trying the solution you wrote. Does it work in release mode as "false"?

@phryneas
Copy link
Member

phryneas commented Feb 7, 2023

The warning occurs if you call .injectEndpoints for the same endpoint name multiple times. I can't tell how that happens in your specific situation. You should definitely avoid that in your code.

@devoren
Copy link
Author

devoren commented Feb 7, 2023

I am calling useLoginMutation when I click a button. I don't have endpoints where I call inside useEffect or multiple times

Api:

const baseUrl = API.HOST;

const baseQuery = fetchBaseQuery({
	baseUrl: baseUrl, 
       ...
});

export const api = createApi({
	reducerPath: 'api',
	baseQuery,
	tagTypes: ['User'],
	endpoints: () => ({}),
});

Inject endpoints:

const userApi = api.injectEndpoints({
	endpoints: (builder) => ({
		login: builder.mutation<AuthResponse & ErrorResponse, LoginRequest>({
			query: (body) => ({
				url: ENDPOINTS.USERS.LOGIN,
				method: 'POST',
				body,
			}),
		}),
		signup: builder.mutation<AuthResponse, SignupRequest>({
			query: (body) => ({
				url: ENDPOINTS.USERS.SIGNUP,
				method: 'POST',
				body,
			}),
		}),
		...
	}),
	 // @ts-ignore
	overrideExisting: module.hot?.status() === "apply",
});

How i call it

const onLogin = () => {
        login(req)
		.unwrap()
		.then((data) => {
			console.log(data)
		});
	}

@devoren
Copy link
Author

devoren commented Feb 7, 2023

I don't know how but the problem disappeared without this solution

That is probably due to hot module reloading reloading the file when you apply changes to it.

You could try adding

overrideExisting: module.hot?.status() === "apply"

to the injectEndpoints call.

@Ashfak-Hossain
Copy link

overrideExisting: module.hot?.status() === "apply"

With this typescript, the error

  • Property 'hot' does not exist on type 'NodeModule'.ts(2339)

I solved it bt utilizing the module as any

overrideExisting: (module as any).hot?.status() === 'apply',

@onesmusmuna
Copy link

Hello Guys,
By adding overrideExisting: true worked for me

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