How to get user identification number in React

To get a user identification number when it accesses to a website, you can use the fingerprintjs package. It will detect a browser with an accuracy of 94%.

The identification number will remain constant if the user accesses to the web using the same browser 94/100 times.

No cookies are stored to identify the browser.

Installation

terminal
npm i --save fingerprintjs

Usage

jsx
import React, { useEffect, useState }   from 'react';
import Fingerprint                      from 'fingerprintjs';

const App = () => {

    const [uid, setUid] = useState(null);

    useEffect ( () => {
    
        let fingerprint = new Fingerprint().get();
        
        setUid(fingerprint);
    
    }, []);

    return (
        
        <div>This is the identificator of the user: {uid}</div>
        
    );

}

export default App;

This package is useful in many cases, for example, to control whether a user is recurrent or not, to create custom content to recurrent users or to prevent to show content if they aren't logged in.

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.