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

react-get-data

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-get-data

Solution for fetching data from service-oriented api layer

  • 0.1.0
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

React get data [GitHub license] [![Npm version])(https://img.shields.io/npm/v/react-get-data.svg)]

A small react wrapper for fetching data from remote services.

Each service is a class:

const services = {
  account: {
    async getAccount(accountId) {
      const { data } = await axios.get(`/accounts/${accountId}`)
      return data
    }
  }
}

Full example:

import { GetData, ServiceProvider } from 'react-get-data'

<ServiceProvider services={services}>
  <GetData
    service="account"
    method="getAccount"
    args={['id0']}
    whilePending={GetAccountSpinner}
  >{(account, error) =>
      error
        ? <GetAccountError error={error} />
        : <DisplayAccount account={account} />
    }
  </GetData>
</ServiceProvider>

Minimal example:

import { GetData, ServiceProvider } from 'react-get-data'

<ServiceProvider services={services}>
  <GetData
    service="account"
    method="getAccount"
    args={['id0']}
  >{
    account => <DisplayAccount account={account} />
  }</GetData>
</ServiceProvider>

GetData

Is a render-prop-enabled component which represents a call for a remote service.

It hooks on componentWillMount and call service's member method with args, and renders whilePending while waiting response.

  • Parameters:
    • service - Required, name of service to pick from context
    • method - Required, name of service's method to call
    • args - Optional, list of arguments of methods
    • whilePending - Optional, this component will be displayed while GetData waiting response from service

ServiceProvider

Is a context provider for a dictionary of services.

  • Parameters:
    • services - Required, dictionary of services

Keywords

FAQs

Package last updated on 04 Mar 2018

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