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-version-tracker

v0.0.5

Published

React version tracker

Downloads

2

Readme

React Version Tracker

This module will be used to detect the version change of the application

Version tracking can be done

What?

  • React version tracker library is used to track app version and inform the user.
  • It has two types of control
    • using hooks
    • using component VersionTracker

Installation

Install react-version-tracker with npm

  npm install react-version-tracker  

Install react-version-tracker with yarn

  yarn add react-version-tracker  

How to use the VersionTracker component

import Component in app level

import { VersionTracker } from 'react-version-tracker';

in app.js add the below code

<VersionTracker 
  currentVersion='v1.0.0'
  versionFileUrl='version.json'  
  onVersionChange={onVersionChange}
  />

PROPTYPES

| Prop | Type | Default | Description |
| ---- | ---- | ------- | ------- | | currentVersion | String | | This will be the current version of the build | | versionFileUrl | String | /version.json | this can be file location or any API | displayAlert | Boolean | false| when there is change alert will be displayed | onVersionChange | Function | | when the version change method will be called | message | String | | user message on the alert box.

Example

versionFileUrl

when we keep the version file in the web server simple pass the file name 
versionFileUrl="version.json". 
or
versionFileUrl="http://text.com/api/get-version"

version.json or api response should be as below.

{ "version":"1.0.0" }

onVersionChange

this funtion will return object {"version":"1.0.0"}

how to use version hooks (useVersionTracker and useVersion)

react-version-tracker has two hooks useVersionTracker and useVersion . we have to do client and server side changes to use hooks

Client side changes

we need to pass response of API to useVersionTracker . it has two params first is the response second one is the key of response header. useVersionTracker hook can be added to the axios response interceptor or in the HTTP service.

Sample 1

import { useVersionTracker } from 'react-version-tracker';

fetch(url, {
      method: method,
      body: JSON.stringify(data),
      headers: headers,
      params: params,
    }).then((response) => {      
      useVersionTracker(response, 'X-Version');     
      return response.json();
    })

Sample 2

import axios from 'axios'
import { useVersionTracker } from 'react-version-tracker';

axios.interceptors.response.use(
  response => {
     useVersionTracker(response, 'x-version') 
    return response
  },function (error) {       
      return Promise.reject(error)
    })

When any version change is detected new version will be returned by useVersion hook

const { version } = useVersion();

  useEffect(() => {
    if (version !== currentVersion) {
      // write your logic here
    }
  }, [version]);

Server side changes

Node JS changes from api response.

let results= {};
response.header('Access-Control-Expose-Headers', 'x-version');
response.set('x-version', '1.0.0');
return response.send(results);

Documentation

Documentation

Roadmap

  • Display modal instead of alert

  • Give the option to auto-reload in VersionTracker

  • Add auto-reload and Display alert option in useVersionTracker

🔗 Links

linkedin twitter