Hoony B
Hoony B

Reputation: 125

How can i make lib file on reactJS

I want to create a global function. For example, create a Javascript file with

function increment (val) {
  return val + 1;
} 

And I want to use this function in app.js or some other component. How do I set up this structure in ReactJS?

Upvotes: 1

Views: 111

Answers (1)

Hai Pham
Hai Pham

Reputation: 2225

Just export your function as a module and import it in app.js

export function increment (val) {
  return val + 1;
} 

Then in your app.js:

import { increment } from 'your_module_path';
//...
    let b = increment(1);

Upvotes: 1

Related Questions