15

In my application I'll store the some data's, so I would use the AsyncStorage method but Now need to create a uuid because AsyncStorage name for same to updated.

any alternative idea for this scenario or how to create UUID.

Not used any npm pakage.

4 Answers4

21

First run the script to install npm package for react-native-uuid

   npm install react-native-uuid --save

After that import the module in your file by

import uuid from 'react-native-uuid';
//usage 
var testUUID = uuid.v1();

You might get an error showing that

module buffer does not exist in react native

if so, install that module too,

 npm install buffer --save

Hope this helps!

Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77
  • 8
    This generates an error like so: "attempted to import the Node standard library module "buffer". It failed because React Native does not include the Node standard library." – Alexus Oct 04 '18 at 02:29
6

Without using a npm already tested code you can create you own function that will generate an UUID for you.

See this question

Community
  • 1
  • 1
K.Ariche
  • 1,188
  • 3
  • 14
  • 29
1

What worked for me was to install uuid-random using.

npm i uuid-random

Then to import,

import uuid from 'uuid-random';

Finally to use,

uuid()

More about uuid-random package

Upulie Han
  • 431
  • 1
  • 7
  • 15
1

We just recently released an updated version of react-native-uuid, fully rewritten in TypeScript.

Here's how to use it:

  1. Install
npm install react-native-uuid
  1. Call
import uuid from 'react-native-uuid';
uuid.v4(); // ⇨ '11edc52b-2918-4d71-9058-f7285e29d894'

More details: https://github.com/eugenehp/react-native-uuid

Eugene Hauptmann
  • 1,255
  • 12
  • 16