Skip to content

Commit

Permalink
feat: apislice gettodos
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasprima committed Mar 19, 2024
1 parent be9b826 commit 570fc58
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/features/api/apiSlice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'

export const apiSlice = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:8080' }),
endpoints: (builder) => ({
getTodos: builder.query({
query: () => '/todos'
})
})
})

export const {
useGetTodosQuery
} = apiSlice
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';

import { ApiProvider } from '@reduxjs/toolkit/dist/query/react';
import { apiSlice } from './features/api/apiSlice';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
<ApiProvider api={apiSlice}>
<App />
</ApiProvider>
</React.StrictMode>
);

0 comments on commit 570fc58

Please sign in to comment.