Skip to content

Instantly share code, notes, and snippets.

@CarmeloRicarte
Created December 8, 2022 09:21
Show Gist options
  • Save CarmeloRicarte/03ece9d664a617423bf3783ec4b0ae36 to your computer and use it in GitHub Desktop.
Save CarmeloRicarte/03ece9d664a617423bf3783ec4b0ae36 to your computer and use it in GitHub Desktop.
Example of how to create an api with RTK Query
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
export const todosApi = createApi({
reducerPath: "todos",
baseQuery: fetchBaseQuery({
baseUrl: "https://jsonplaceholder.typicode.com",
}),
endpoints: (builder) => ({
getTodos: builder.query({
query: () => "/todos",
}),
}),
});
// export endpoints as custom hooks for use it in your app
export const { useGetTodosQuery } = todosApi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment