ReSift

ReSift

  • Docs
  • API
  • Help
  • GitHub

›API

Introduction

  • What is ReSift?
  • Installation

Tutorial

  • ReSift Rentals

Main Concepts

  • What's a fetch?
  • How to define a fetch
  • Making state consistent
  • Making sense of statuses
  • What are data services?
  • Error handling
  • Custom hooks

Examples

  • ReSift Notes (CRUD)
  • Infinite scroll
  • Custom hooks and React Router

Guides

  • ReSift vs Apollo and Relay
  • HTTP proxies
  • Usage with TypeScript
  • Usage with Redux
  • Usage with classes

API

  • About these docs
  • useStatus
  • useError
  • useDispatch
  • useData
  • useClearFetch
  • isUnknown
  • isNormal
  • isLoading
  • isError
  • defineFetch
  • dataServiceReducer
  • createStoreKey
  • createHttpService
  • createHttpProxy
  • createDataService
  • createActionType
  • combineStatuses
  • ResiftProvider
  • Guard
  • CanceledError
  • UNKNOWN
  • NORMAL
  • LOADING
  • ERROR
Edit

createDataService API

These docs are auto-generated from typings files (*.d.ts).

createDataService

Creates the data service to be feed into the <ResiftProvider dataService={dataService} /> or in Redux middleware.

function createDataService(params: DataServiceParams): any;

DataServiceParams

You must provide an object with the following shape into createDataService. See What are data services for more info.

NameDescriptionTypeRequired
servicesDefines the shape of the data services object you can destructure in the request body of a
fetch factory.
See here for more info.
{ [key: string]: FetchService }yes
onErrorThis callback fires when any promise throws or catches with an error from a fetch service.
If you're unsure how to handle this error, re-throw:
onError: e => { throw e; }
(error: Error) => voidyes

FetchService

A fetch service is a function that returns data asynchronously. This data is given to ReSift for storage and retrieval.

See What are data services? for more info.

See createHttpService for a reference implementation of a fetch service.

type FetchService = {
  (params: FetchServiceParams): T | Promise;
};

FetchServiceParams

The data service provides fetches services with this object. Fetch services are expected to use these params to implement cancellation correctly.

NameDescriptionTypeRequired
onCancelAdds a callback listener to the cancellation mechanism. If the request is cancelled, the
callback given will be invoked.

See createHttpService
for a reference implementation
(callback: () => void) => voidyes
getCanceledReturns whether or not the request has been cancelled. Use this in conjunction with
CanceledError to early exit when a cancellation occurs.

See createHttpService
for a reference implementation
() => booleanyes

ServicesFrom

This is a typescript only module. It's used to get the type of the services object. See here for more info.

type ServicesFrom<
  ServicesObject extends { [key: string]: (...args: any[]) => any }
> = {
  [P in keyof ServicesObject]: ReturnType<ServicesObject[P]>;
};
← createHttpProxycreateActionType →
  • createDataService
  • DataServiceParams
  • FetchService
  • FetchServiceParams
  • ServicesFrom
ReSift
Docs
What is ReSift?What's a fetch?API
Community
Ask a questionOpen an issue@ meLeave feedback
More
StarBuild StatusCoverage Status
Copyright © 2021 Sift
www.justsift.com