├── README.md ├── .gitattributes ├── .DS_Store └── src ├── index.css ├── reportWebVitals.js ├── app └── store.js ├── services └── users.js ├── App.js ├── index.js └── App.css /README.md: -------------------------------------------------------------------------------- 1 | # react-redux-toolkit-rtk-query 2 | 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmilAbdullazadeh/react-redux-toolkit-rtk-query/HEAD/.DS_Store -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /src/app/store.js: -------------------------------------------------------------------------------- 1 | import { configureStore } from "@reduxjs/toolkit"; 2 | import { setupListeners } from "@reduxjs/toolkit/query"; 3 | import { usersApi } from "../services/users"; 4 | 5 | export const store = configureStore({ 6 | reducer: { 7 | [usersApi.reducerPath]: usersApi.reducer, 8 | }, 9 | middleware: (getDefaultMiddiware) => 10 | getDefaultMiddiware().concat(usersApi.middleware), 11 | }); 12 | 13 | setupListeners(store.dispatch); 14 | -------------------------------------------------------------------------------- /src/services/users.js: -------------------------------------------------------------------------------- 1 | import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react"; 2 | 3 | export const usersApi = createApi({ 4 | reducerPath: "users", 5 | baseQuery: fetchBaseQuery({ 6 | baseUrl: "https://jsonplaceholder.typicode.com", 7 | }), 8 | endpoints: (builder) => ({ 9 | getUsers: builder.query({ 10 | query: () => `users`, 11 | }), 12 | }), 13 | }); 14 | 15 | export const { useGetUsersQuery } = usersApi; 16 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import { useGetUsersQuery } from "./services/users"; 3 | 4 | function App() { 5 | const { data, error, isLoading, isSuccess, isError } = useGetUsersQuery(); 6 | 7 | return ( 8 |