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

@teamleader/react-hooks-api

Package Overview
Dependencies
Maintainers
12
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teamleader/react-hooks-api

React hooks for the Teamleader API

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
12
Created
Source

🎣 @teamleader/react-hooks-api

React hooks for the Teamleader API

Installation

yarn add @teamleader/react-hooks-api

or

npm install --save @teamleader/react-hooks-api

Getting started

Wrap your root inside the Provider component and provide an initialized @teamleader/api config.
import React from 'react';
import { Provider } from '@teamleader/react-hooks-api';
import { API as initializeAPI } from '@teamleader/api';

import App from '../App';

const API = initializeAPI({...})

const Root = () => {
  return (
    <Provider api={API}>
      <App />
    </Provider>
  );
}

export default Root;
You can now start using useQuery in your components to fetch data.
import React from 'react';
import { useQuery } from '@teamleader/react-hooks-api';

const QUERY = () => ({
  domain: 'projects',
  action: 'list',
});

const Component = () => {
  const { loading, error, data } = useQuery(QUERY);

  if (loading || !data) {
    return 'Loading...';
  }

  if (error) {
    return 'Error';
  }

  if (data) {
    return data;
  }

  // default
  return null;
};

export default Root;

API

useQuery

Signature: (query: Query, variables: Variables, options: Options) => QueryValues

Query

Variables

QueryValues

Options

Query

A function that returns an object. This function can be defined with variables when you need to update it dynamically.

Variables

The variables to be passed to the Query. When updated, it will re-run the query.

QueryValues

loading: Boolean
error?: Error
data?: Response

Options

{
  ignoreCache: boolean; // default: false
}

Keywords

FAQs

Package last updated on 11 Jul 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