26

Hooks to fetch data in react.js! TS and SSR support! Check out new version

 5 years ago
source link: https://www.tuicool.com/articles/hit/Nr2AviF
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

22aUjiB.png!web

Simple and powerful fetching library for React. Use hooks to fetch data!

:white_check_mark: Zero dependencies (react, react-dom as peer deps)

:white_check_mark: SSR support

:white_check_mark: Use hooks or FACC's (Function as Child Components) - depending on your needs

:white_check_mark: Uses Fetch API

:white_check_mark: Request and response interceptors allows to easily customize connection with API

:white_check_mark: React Suspense support

:white_check_mark: TypeScript support

:white_check_mark: 2.2k minizipped

:white_check_mark: Simple cache provider - easily to extend

react-fetching-library

Use hooks or FACC's (Function as Child Component) to fetch data in an easy way. No dependencies! Just React under the hood.

Request and response interceptors allows you to easily customize connection with API (add authorization, refresh token, cache, etc). It uses Fetch API so it can be use in SSR apps (ie. with isomorphic-fetch)

Library allows you to use it with connection of React Suspense ( read more about React Suspense ) to easily maintain loading state in application.

Documentation

Full documentation is available at https://marcin-piela.github.io/react-fetching-library

Short example of use

import { useQuery } from 'react-fetching-library';

const fetchUsersList = {
  method: 'GET',
  endpoint: '/users',
};

export const UsersListContainer = () => {
  const { loading, payload, error, query } = useQuery(fetchUsersList);

  return <UsersList loading={loading} error={error} users={payload} onReload={query} />;
};

Typescript support

QfMrmmY.gif

Inspirations

Contributing

Fell free to open PRs and issues to make this library better !

When making a PR, make sure all tests pass. If you add a new feature, please consider updating the documentation or codesandbox examples. Thank you!

License

react-fetching-library is licensed under the MIT license .


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK