1

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?

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.