Search code examples
react-nativeexpouuid

Crash in react-native-Uuid-generator when using library in expo app


I want to generate a uuid in ReactNative app built with expo cli.. when I install UUIDGenerator from React-native-uuid-generator, I get undefined is not an object(evaluating ‘RNUUIDGenerator.getRandomUUID’..)

Tried two dif libraries, react-native-uuid, and React-native-uuid-generator, same problem, think it might have to do with expo not liking the link command.

UUIDGenerator.getRandomUUID().then(uuid => console.log(uuid));

Expecting new uuid to be printed, actually getting error message.


Solution

  • react-native-uuid works with expo.

    npm install react-native-uuid --save
    
    import uuid from 'react-native-uuid';
    

    then generatte uuid like

    const uuid = uuid.v1();