Top React Hooks — Async and Window

Photo by Dan Gold on Unsplash

Hooks contains our logic code in our React app.

We can create our own hooks and use hooks provided by other people.

In this article, we’ll look at some useful React hooks.

React Recipes

React Recipes comes with many hooks that we can use to do various things.

The useWindowSize hook lets watch the size of the window as it changes.

For instance, we can write:

import React from "react";
import { useWindowSize } from "react-recipes";
export default function App() {
const { width, height } = useWindowSize();
return (

We call the useWindowSize hook to return the width and height properties.

They’re the width and height of the window.

We can also pass in the initial width and height, which are useful for server-side rendered apps.

It comes with many other useful hooks to make our lives easier.

React Request Hook

The React Request Hook library lets us make requests with ease.

To install it, we run:

yarn add react-request-hook axios


npm install --save react-request-hook axios

Then we can use it by writing:


import React from "react";
import ReactDOM from "react-dom";
import { RequestProvider } from "react-request-hook";
import axios from "axios";
import App from "./App";
const axiosInstance = axios.create({
baseURL: ""
const rootElement = document.getElementById("root");
<RequestProvider value={axiosInstance}>
<App />


import React from "react";
import { useResource } from "react-request-hook";
export default function App() {
const [name, getName] = useResource(name => ({
url: `/?name=${name}`,
method: "get"
React.useEffect(() => {
}, []);
return <div>{JSON.stringify(name)}</div>;

In index.js , we create the Axios instance and pass it into the RequestProvider component.

The value prop takes the Axios instance.

Then we can use the useResource hook in App to get the data we want.

In the callback we pass in, we return the url and method .

The url is the path relative to the URL in the Axios instance.

method is the request method.

It returns an array with the result and the function to get the result.

name has the response body.

And getName is a function that takes the same parameter as the useResource callback to get the data.

Then we can call getName to get the data.

It also provides us with other ways to make requests.


React-RocketJump is another library that lets us commit async side effects in our React app.

To use it, we install it by running:

yarn add react-rocketjump

Then we can use it by writing:

import React from "react";
import { rj, useRunRj } from "react-rocketjump";
const NameState = rj({
effect: () => fetch(``).then(r => r.json())
export default function App() {
const [{ data: name, pending, error }] = useRunRj(NameState);
return (
{error && <div>Got some troubles</div>}
{pending && <div>Wait...</div>}

We create our side effect with the rj function.

The object has the effect method which returns a promise with the data.

Then in App , we use the useRunRj hook to get the data.

We pass in NameState as the argument of the hook.

Then it returns an array with an object that has the data , pending , and error properties.

data has the response body.

pending has the pending status.

error has the error.

Photo by Maddi Bazzocco on Unsplash


React Recipes, React Request Hook, and React-RocketJump are all useful libraries that give us various hooks to do what we want.

Web developer. Subscribe to my email list now at Email me at

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store