New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bsara/react-use-fetch

Package Overview
Dependencies
Maintainers
1
Versions
12
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

@bsara/react-use-fetch

react-use-fetch =========================================================================================

1.0.0-beta.1
unpublished
Source
npm
Version published
Maintainers
1
Created
Source

react-use-fetch

React hooks for interacting with the fetch API which includes the ability to add middleware to intercept, modify, cancel, cache, or analyze fetch calls.

Installation

$ npm i -S @bsara/react-use-fetch

Basic Usage

Basic Usage (Immediate Execution)

import { useFetchGet } from '@bsara/react-use-fetch';

export function MyComponent() {
  const { loading, error, value: movie } = useFetchGet<Movie>('/api/movies/42'); // NOTE: Only submits request if URL changes.
  
  return (
    loading ? <div>Loading...</div>
      : error ? <div>Error: {error.message}</div>
      : <div>{movie.title} ({movie.year}) by {movie.director}</div>
  );
}

type Movie = {
  id: number;
  title: string;
  year: number;
  director: string;
};

Basic Usage (On-Demand Execution)

import { useState } from 'react';
import { useFetchGetFn } from '@bsara/react-use-fetch';

export function MyComponent() {
  const [ { loading, error, value: movie }, fetchMovie ] = useFetchGetFn<Movie>(`/api/movies/42`);

  return (
    loading ? <div>Loading...</div>
      : error ? <div>Error: {error.message}</div>
      : movie ? <div>{movie.title} ({movie.year}) by {movie.director}</div>
      : <button onClick={fetchMovie}>Fetch It!</button>
  );
}

Add "Standard" Options for All Requests (Without Provider)

// main.ts

import { addUseFetchMiddleware } from '@bsara/react-use-fetch';
import standardOptionsMiddleware from '@bsara/react-use-fetch/middleware/standard-options';

addUseFetchMiddleware(standardOptionsMiddleware);

// ...

Advanced Usage

TODO

Adding Middleware

TODO

Aborting a Request

TODO

Hooks

Middleware

TODO

Provided Middleware

FAQs

Package last updated on 08 Nov 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