New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

cachebolt

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

cachebolt

---

unpublished
latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

CacheBolt Documentation

Got it! Based on the information you provided, I can generate the documentation for your npm package called CacheBolt. Here's an example template for the documentation:

CacheBolt

CacheBolt is an npm package built for React that allows you to fetch data from an API, cache it, and store it in Redux using Redux Toolkit and Redux Saga. It provides intuitive hooks for performing queries and mutations, as well as a hook for configuring global options.

Installation

You can install CacheBolt using npm or yarn:

npm install cachebolt

or

yarn add cachebolt

Usage

To use CacheBolt in your React application, you need to have Redux and Redux Saga set up. Once you have those dependencies installed and configured, you can start using CacheBolt.

1. Importing

Import the necessary hooks from the cachebolt package:

import { useCacheBoltQuery, useCacheBoltMutation, useSetBaseConfiguration } from 'cachebolt';

2. Querying Data

To perform a query and fetch data from the API, use the useCacheBoltQuery hook. Here's an example:

const MyComponent = () => {
  const { data, isLoading, error } = useCacheBoltQuery('users', {
    tags:['getUsers']
  });

  if (isLoading) {
    return <div>Loading...</div>;
  }

  if (error) {
    return <div>Error: {error.message}</div>;
  }

  return (
    <div>
      {data.map((user) => (
        <div key={user.id}>{user.name}</div>
      ))}
    </div>
  );
};

3. Mutating Data

To perform a mutation and send data to the API, use the useCacheBoltMutation hook. Here's an example:

const MyComponent = () => {
  const { mutate, isLoading, error } = useCacheBoltMutation('createUser', {
    invalidateTags: ['getUsers']
  });

  const handleSubmit = async (data) => {
    try {
      await mutate(data);
      console.log('User created successfully!');
    } catch (e) {
      console.error('Error creating user:', e);
    }
  };

  if (isLoading) {
    return <div>Loading...</div>;
  }

  if (error) {
    return <div>Error: {error.message}</div>;
  }

  return (
    <div>
      <form onSubmit={handleSubmit}>
        {/* form fields */}
        <button type="submit">Create User</button>
      </form>
    </div>
  );
};

Table of Contents

  • useSetBaseConfiguration
  • useCacheBoltQuery
  • useCacheBoltMutation

useSetBaseConfiguration

The useSetBaseConfiguration hook is used to configure the base options for CacheBolt.

Usage

useSetBaseConfiguration(options);

Parameters

  • options (object): The configuration options.

Options

The options object accepts the following properties:

  • baseUrl (string, required): The base URL for the API.
  • expirationTime (number): The global expiration time in seconds. This can be overridden by individual expirationTime properties.
  • disableCaching (boolean): If set to true, caching will be disabled.
  • headers (Headers): Additional headers to be included in each request.
  • customFetchFunction ((endpoint: string) => Promise): A custom fetch function to use for making API requests.
  • method (string): The HTTP method to use for requests.

useCacheBoltQuery

The useCacheBoltQuery hook is used to perform queries and fetch data from the API.

Usage

const queryResult = useCacheBoltQuery(endpoint, requestOptions);

Parameters

  • endpoint (string): The API endpoint to query.
  • requestOptions (object): The request options.

RequestOptions

The requestOptions object accepts the following properties:

  • effect ("takeLatest" | "takeLeading" | "takeEvery"): The effect type for handling concurrent requests.
  • method (string): The HTTP method to use for the request.
  • disableCaching (boolean): If set to true, caching will be disabled for this query.
  • fetchFunction ((endpoint: string) => Promise): A custom fetch function to use for this query.
  • tags (array): An array of tags associated with the query.

Query Result

The useCacheBoltQuery hook returns a query result object with the following properties:

  • data (T | undefined): The fetched data.
  • isLoading (boolean): A flag indicating if the query is in progress.
  • isError (boolean): A flag indicating if an error occurred during the query.
  • error (Error | undefined): The error object, if any.
  • paginationOptions (object): The pagination options for the query.
  • refetch (function): A function to manually trigger a refetch of the query.

Pagination Options

The paginationOptions object is retrieved using the usePagination function and provides pagination-related functionalities. Refer to the usePagination hook documentation for more details.

This concludes the updated documentation for the useCacheBoltQuery hook. For more details and examples, please refer to the documentation provided above.

useCacheBoltMutation

The useCacheBoltMutation hook is used to perform mutations and send data to the API.

Usage

const { mutate } = useCacheBoltMutation(endpoint, requestOptions);

Parameters

  • endpoint (string): The API endpoint for the mutation.
  • requestOptions (object): The request options.

RequestOptions

The requestOptions object accepts the same properties as the requestOptions object in useCacheBoltQuery.

This concludes the documentation for the CacheBolt npm package. For more details and examples, please refer to the specific hook sections above.

Keywords

container

FAQs

Package last updated on 20 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts