ReSift

ReSift

  • Docs
  • API
  • Help
  • GitHub

โ€บGuides

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

Usage with classes

Disclaimer: ReSift is meant to be used with function components because we use hooks to drive our APIs.

However, we acknowledge that you can't rewrite you application. This guide is meant to show you how to use ReSift with you existing components for compatibility's sake. If you're creating new experiences, we strongly advise you to use function components.

In order to use ReSift's hooks with your existing class components, we recommend using the library hocify aka higher-order-component-ify.

This library lets you use hooks within class components by wrapping your hooks with a function component internally.

See this example:

import { Component } from 'react';
import { useStatus, Guard } from 'resift';
import hocify from 'hocify';
import makeGetPerson from './makeGetPerson';

//                                    ๐Ÿ‘‡ these are incoming props
const withFetchAndStatus = hocify(({ personId }) => {
  const getPerson = makeGetPerson(personId);
  const status = useStatus(getPerson);

  // these will be injected as props
  //        ๐Ÿ‘‡
  return { getPerson, status };
});

class MyExistingComponent extends Component {
  render() {
    const { getPerson, status } = this.props;

    return (
      <div>
        {isLoading(status) && (
          <div className="overlay">
            <Spinner />
          </div>
        )}
        <Guard fetch={getPerson}>{(person) => <h1>{person.name}</h1>}</Guard>
      </div>
    );
  }
}

export default withFetchAndStatus(MyExistingComponent);
Last updated on 4/1/2020
โ† Usage with ReduxAbout these docs โ†’
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