React Boilerplate Redux Saga Hoc

Search Results

No results for 'N/A'
1. Getting Started
2. Basic Concepts
2.1 Storing Data2.2 Updating Data2.3 Handling Infinite Data2.4 Deleting Data# Deleting data by calling api# Deleting key in an object# Manually Deleting by calling custom task# Getting Data from store2.5 Adding Filters2.6 Using Subkey
3. Handlers
4. Advanced Concepts
5. Examples6. Advanced Examples7. ParamsApi ReferenceComplete DocumentationPrevious DocumentationReadme

Deleting Data

# Deleting data by calling api

Note:
-Data will be deleted automatically in the reducer and also it handles all the states..such as error,infinte,loader..etc
const BASE_URL = "https://example.com/";
const DEMO_API_CONFIGURATION = {
url: ({ id }) => `${BASE_URL}user/${id}`,
method: "DELETE",
responseStatusCode: [900],
responseStatusCodeKey: "code",
responseDataKey: "data",
responseMessageKey: "status",
errorMessageKey: "error",
};
DEMO_API_CONFIGURATION_CALL({
task: {
name: "Delete-Handler",
key: "id",
id: [2],
},
request: {
params: { id: 2 },
},
});
Note:
-It will remove that particular object in an array

# Deleting key in an object

Note:
-It is almost similar to update, but instead of updating particular key it will delete the particular key from the object
const BASE_URL = "https://example.com/";
const DEMO_API_CONFIGURATION = {
url: ({ id }) => `${BASE_URL}user/${id}`,
method: "DELETE",
responseStatusCode: [900],
responseStatusCodeKey: "code",
responseDataKey: "data",
responseMessageKey: "status",
errorMessageKey: "error",
};
DEMO_API_CONFIGURATION_CALL({
task: {
name: "Delete-Key-Handler",
id: [1, 2, 3],
key: "id",
deleteKey: ["name", "age"],
},
request: {
params: { id: 1 },
},
});
/*
Example:
data = [ { id: 1, name: 'name1',age: '13',gender: 'male' },{ id: 1, name: 'name1',age: '12',gender: 'female' }]
After executing task:
data = [ { id: 1, gender: 'male' },{ id: 2, gender: 'female' }]
*/

# Manually Deleting by calling custom task

Note:
-Calling custom task will allow us to manipulate data without calling any api..such as adding count,linit,skip..etc
import { HOC, commonConstants, store } from "react-boilerplate-redux-saga-hoc";
const { ON_SUCCESS } = commonConstants;
const { DEMO_API_CONFIGURATION_CUSTOM_TASK } = props;
DEMO_API_CONFIGURATION_CUSTOM_TASK(ON_SUCCESS, {
task: {
name: "Delete-Handler",
id: [1, 2],
key: "id",
},
});

# Getting Data from store

import { useMemo } from "react";
import { useQuery } from "react-boilerplate-redux-saga-hoc";
const {
Auth_hoc: {
reducerName,
reducerConstants: { DEMO_API_CONFIGURATION },
},
} = props;
const { loader, data, lastUpdated, isInfinite, infiniteEnd } = useQuery(
reducerName,
DEMO_API_CONFIGURATION
);

Next - Adding Data based on filters