ReSift

ReSift

  • Docs
  • API
  • Help
  • GitHub

›Introduction

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

Installation

Installation

npm i resift redux react-redux

or if you're using yarn

yarn add resift redux react-redux

Redux 4 and React-Redux >= 7.1 are required peer dependencies to ReSift, However, we may remove these dependencies in the future.

⚠️ If you're already using Redux in your project, follow this guide here.

Creating the data service and HTTP service

Create a file called dataService. Create a data service instance and then export it.

dataService.js

import { createHttpService, createDataService } from 'resift';

const http = createHttpService({
  // if all your endpoints share the same prefix, you can prefix them all here
  prefix: '/api',
  // if you need to add headers (for auth etc), you can do so using `getHeaders`
  getHeaders: () => {
    const token = localStorage.getItem('auth_token');

    return {
      Authorization: `Bearer ${token}`,
    };
  },
});

const dataService = createDataService({
  services: { http },
  onError: (e) => {
    // see https://resift.org/docs/main-concepts/error-handling for more info
    // on how to handle errors in resift.
    throw e;
  },
});

export default dataService;

Adding the <ResiftProvider />

Lastly, wrap your application in the ResiftProvider. This will enable all the hooks APIs.

App.js

import React from 'react';
import { ResiftProvider } from 'resift';
import RestOfYourApplication from '...';

// import the data service we just created
import dataService from './dataService';

function App() {
  return (
    <ResiftProvider dataService={dataService}>
      <RestOfYourApplication />
    </ResiftProvider>
  );
}
Last updated on 4/1/2020
← What is ReSift?ReSift Rentals →
  • Installation
  • Creating the data service and HTTP service
  • Adding the <ResiftProvider />
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