This package has been deprecated in favour of using react-query.
React hooks for the Teamleader API
yarn add @teamleader/react-hooks-apior
npm install --save @teamleader/react-hooks-apiWrap 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;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;Signature: (query: Query, variables: Variables, options: Options) => QueryValues
A function that returns an object. This function can be defined with variables when you need to update it dynamically.
The variables to be passed to the Query. When updated, it will re-run the query.
loading: Boolean
error?: Error
data?: Response
{
ignoreCache: boolean; // default: false
}