0.6.0 • Published 3 years ago

@mychi/react-hermes v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Hermes

Hermes is a simple library for React that makes working with axios really simple. Hermes provides a hermes class which can be used for configuration and making requests. It also comes with hooks and a general method which can be used from anywhere in your app.

Hermes has a 100% TypeScript support as it was created with TypeScript.

Hermes Class

The hermes class can be used to configure hermes using the config method.

config

import Hermes from "react.hermes";

Hermes.config({
  baseUrl: "https://me.com/api/";
});

You can also use config to retrieve the value for a particular configuration value by passing in a string instead of an object.

const baseUrl = Hermes.config("baseUrl");

request

Request allows you to quickly make a hermes request...

Hooks

Hermes comes with react hooks which come with a lot more functionality like background refreshes.

useHermes

useHermes is the most the most basic hermes hook, as all other hooks are based on it. You can make a request like this.

const FetchUsers = () => {
  const [res, loading, error] = useHermes("/users");

  const users = res?.data?.data?.users;

  return loading ? <Loader /> : (
    <div>
      {error && <Error err={error} />}
      {users && <Users data={users} />}
    </div>
  );
};