I am new to react native and working on my first project in expo. I am trying to generate unique id for every order that is being placed by the user, below is what I have tried
const orderId = () => {
var S4 = () => {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
return (
S4() +
S4() +
"-" +
S4() +
"-" +
S4() +
"-" +
S4() +
"-" +
S4() +
S4() +
S4()
);
};
console.log(orderId);
what I am getting in terminal is [Function orderId]
You can use the following:
https://www.npmjs.com/package/react-native-uuid
npm install react-native-uuid
import uuid from 'react-native-uuid';
uuid.v4(); // ⇨ '11edc52b-2918-4d71-9058-f7285e29d894'
If you are not able to use other libraries in your project see the following related question:
How to create a GUID / UUID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With