I have a place wherein I am required to use npm uuid package for generating unique Id's. After installing uuid package, the usage is as follows:
const uuid = require('uuid/v1');
uuid();
But I have error which says:
[eslint] Unexpected require(). (global-require)
My function is as below:
someFunction = (i, event) => {
if(someCondition) {
//generate some unique id
const uuid1 = require('uuid/v1');
uuid1();
//call some function and pass this id
someFunction2(uuid1);
} else{
//generate some unique id
const uuid2 = require('uuid/v1');
uuid2();
//call some function and pass this id
someFunction2(uuid2);
}
What is the best way to use require in ReactJs.
if(a){ require('')} else {require('')}. The question was why have you written the code this way? Why can't you just doimport uuid1 from 'uuid/v1'at the top of your file?