Answers for "uuid npm typescript"

1

create uuid typescript

// Method 1: use 'uuid' NPM library
//  $ npm i uuid

import { v4 as uuid } from 'uuid';
// ----------------or----------------
const uuid = require('uuid/v4');

const myUUID = uuid();

// Method 2: manually write uuid function
const uuid = () =>
  "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
    var r = (Math.random() * 16) | 0,
      v = c == "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });

const myUUID = uuid();

/*
	Hope this answered your question. Happy coding :)
*/
Posted by: Guest on May-07-2021
5

uuid react

import React from 'react'
import uuid from 'react-uuid'

const array = ['one', 'two', 'three']

export const LineItem = item => <li key={uuid()}>{item}</li>

export const List = () => array.map(item => <LineItem item={item} />)
Posted by: Guest on July-20-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language