Forem

Jeon
Jeon

Posted on • Edited on

UUID libraries for React Native

1. react-native-uuid

⚠️ Caution
react-native-uuid appears to support up to v5 at the time of writing.

npm install react-native-uuid
Enter fullscreen mode Exit fullscreen mode
import uuid from 'react-native-uuid';
uuid.v4();
Enter fullscreen mode Exit fullscreen mode

2. uuid (and plus)

npm install uuid react-native-get-random-values
npx pod-install
Enter fullscreen mode Exit fullscreen mode
import 'react-native-get-random-values'; // This must precede `uuid`
import { v4 as uuidv4 } from 'uuid';
uuidv4();
Enter fullscreen mode Exit fullscreen mode

Top comments (4)

Collapse
 
metal3d profile image
Patrice Ferlet

I really don't understand why not using the browser built-in crypto.randomUUID()

Collapse
 
somidad profile image
Jeon • Edited

That is v4 only. But your comment is also good if v4 is enough.

Collapse
 
metal3d profile image
Patrice Ferlet

Yes :) but your article is for v4 too

Thread Thread
 
somidad profile image
Jeon

Yeah. The examples might be too simple. Both libs support other versions as well as v4.

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay