Socket
Socket
Sign inDemoInstall

@softbind/hook-use-fetch

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @softbind/hook-use-fetch

`npm i @softbind/hook-use-fetch --save`


Version published
Maintainers
1
Install size
11.4 kB
Created

Readme

Source

useFetch

Installation

npm i @softbind/hook-use-fetch --save

API

useFetch(text)

Arguments
  • url: String | () => Promise<any>: url to api or function which need to return promise.
  • opt: Object: you can pass all options that occur in Request
import { useFetch } from "@softbind/hook-use-fetch";

const PageTemplate = () => {
  const { loading, result, cancel, invoke } = useFetch('http://api.im?query=Dog')

  if (loading) {
    return (
      <span>Loading...</span>
    )
  }

  return (
    <div>
      {result ? JSON.stringify(result), null, 2) : null}
      {loading && <button onClick={invoke}>Refresh</button>}
      {!loading && <button onClick={cancel}>Cancel</button>}
    </div>
  );
};

Keywords

FAQs

Last updated on 05 Mar 2019

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc