npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-use-heroku

v1.0.6

Published

Awake a sleepy Heroku, then load the rest of your react application

Downloads

7

Readme

react-use-heroku

NPM version Bundle size Bundle size

Have you deployed any of your projects on Heroku's Free Plan? You definitely noticed your app sleeps after 30 minutes of inactivity. react-use-heroku is custom hook that fetchs an endpoint on your server to wake up heroku. At this point, render a loading message, once successful, load your app.

🚨Note: This package doesn't ping heroku every 30 minutes to wake it up. All this hook accomplishes, is preventing your application from rendering a blank screen initially, instead it will render loading text (or whatever else you wish) until the server is available.

Install

$ npm i react-use-heroku
$ yarn add react-use-heroku

Requirement

This package only works in versions of React that support Hooks.

Usage: Example Client

Parameters

You pass useHeroku an object with the following properties.

| Key | Description | | :--------- |:------------------------------------------------------ | | url | The endpoint to fetch in your api, to wake-up heroku |

Returned

A boolean, true by default, will be set to false once the server is ready.

import React from 'react';
import useHeroku from 'react-use-heroku';

const url = 'https://.........herokuapp.com/wake-up';

const App = () => {
    const isHerokuLoading = useHeroku({ url });

    if (isHerokuLoading) return <div>Heroku is sleeping, hang tight..</div>;

    return (
        <div>
            Welcome to My React App
        </div>
    );
};

export default App;

Usage: Example Api

An extremely simple Express Server

const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const http = require('http');
const logger = require('morgan');

const app = express();
const server = http.createServer(app);

const PORT = process.env.PORT || 4000;

// MIDDLEWARE
app.use(cors());
app.use(logger('tiny'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// THIS IS THE ENDPOINT WE ARE REQUESTING FROM OUR CLIENT TO WAKE-UP HEROKU
app.get('/wake-up', (_, res) => res.json({ status: 'Awake' }));

// START SERVER
server.listen(PORT, () => console.log(`Server listening on port ${PORT}`));

Sample Apps

Here is a list of apps using react-use-heroku. If you have an app you would like to include on this list, open a PR.

  1. BigPlant Demo App by GainorB