Rtk query apiSlice

    0

    0

    YusifHasanov

    createApi() creates an export const that you can use in your code. reducerPath is an optional parameter and defaults to api . baseQuery is a function that takes an object and returns a string. The object must have the following properties: baseUrl and tagTypes . The first property specifies the URL for the API and the second specifies the types of entities that the API will return. For example, if you want to list all the products, you would use baseQuery("product") . If you want to list all the users, you would use baseQuery("user") . tagTypes is an object that specifies the types of entities that the API will return. endpoints is a function that takes a builder and returns an object. builder is a function that takes an object and returns a response. The object must have two properties: action and response. action is a function that takes an object and returns a string. For example, if you want to create a new user, you would use action("create") . response is a function that takes an object and returns a string. For example, if you want to get the user's latest order, you would use response("status") .

    Library: react

    import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
    
    
    
    export const apiSlice = createApi({
      reducerPath: 'api', // optional
      baseQuery: fetchBaseQuery({ baseUrl: "http://localhost:3000/" }),
      tagTypes: ['Cart', 'User',"News","Category","Product"],
      endpoints: builder => ({})
    })
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.