Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hpe/react-hooks

Package Overview
Dependencies
Maintainers
4
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hpe/react-hooks

Reusable react hooks.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

HPE JS Reusable React Hooks

A set of reusable React hooks to use in your React >= v16.8.0 projects.

useFetcher

A set of hooks for fetching asynconchronus data. Uses isomorphic-fetch to allow for server-side rendering. Here's how to use this hook in your React project.

  1. npm install -D @hpe/react-hooks or yarn add @hpe/react-hooks
  2. Import the hook at the top of your componenet file import { useFetcher } from '@hpe/react-hooks';
  3. In your component add const [data, loading, error] = useFetcher('https://myapi/data');. When data is available it will return a json parsed object, loading returns a boolean to allow a loading state while error will provide any request errors the hook encountered.

useFetcher accepts a second parameter to accomplish more customized requests, the second parameter behaves exactly a standard fetch call. More information can be found in the fetch spec.

Below is an example React component using the useFetcher hook.

import React from 'react';
import { useFetcher } from '@hpe/react-hooks';

function App() {
  const [data, loading, error] = useFetcher(
    'https://api.openweathermap.org/data/2.5/weather?zip=27278&appid=18ef348ece45174572c5e3d4be8a8d69&units=imperial',
  );
  return (
    <div>
      {loading && <div>Loading...</div>}
      {error && (
        <div>
          This error happened:{' '}
          <span style={{ background: '#d14545', padding: '2px 5px' }}>
            {error.toString()}
          </span>
        </div>
      )}
      {data && (
        <div>
          {data.name} is {data.main.temp} degrees.
        </div>
      )}
    </div>
  );
}

export default App;

FAQs

Package last updated on 16 Aug 2019

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc