I am creating a progressive web app using react and webpack. I have successfully configured everything and able to start the development. Now, i have many helper functions like :
function getCookie(name) {
var start = document.cookie.indexOf(name + "=");
var len = start + name.length + 1;
if ((!start) && (name != document.cookie.substring(0, name.length))) {
return null;
}
if (start == -1) return null;
var end = document.cookie.indexOf(';', len);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(len, end));
}
So, for this i have created another js file : helper.jsx. Now my helper.js contains the above function as it is. Now i want to use the above function in another react component.
I am doing a require in my component :
var helper = require("helper");
and trying to call the function using :
helper.getCookie('user');
Which is giving me helper.getCookie is not a defined. Please tell me how can i create a helper js and use the functions of helper js in my react components.