0

I have a component that sets up a service and I need to receive that service in other components of my application.

Here's the setup code:

export const setupRemote = () => {
  if (isRemoteAvailable) {
    try {
      ...

      const allowAppInstance = SetupConfig.start(remoteInstance);

      window.setup = {
        someconfig: anothercode,
        code: somecode,
      };
    } catch (e) {
      console.error(e);
    }
  }
};

I need to return the const allowAppInstance, and I tried to do that

export const setupRemote = () => {
  if (isRemoteAvailable) {
    try {
      ...

      const allowAppInstance = SetupConfig.start(remoteInstance);

      window.setup = {
        someconfig: anothercode,
        code: somecode,
      };

      return { 
         allowAppInstance
      }
    } catch (e) {
      console.error(e);
    }
  }
};

But I can't use the return, in es-lint this error occurs -- Expected to return a value at the end of arrow function

How can I return this const to use in other parts of my application?

CodeG
  • 417
  • 2
  • 6
  • 15
  • 1
    It's just warning that you are only returning a value in the case of success, otherwise there is no return value, return from the catch as well or disable the warning. also see: [consistent-return](https://eslint.org/docs/rules/consistent-return) and [How do I fix “Expected to return a value at the end of arrow function” warning?](https://stackoverflow.com/questions/45014094/how-do-i-fix-expected-to-return-a-value-at-the-end-of-arrow-function-warning) – pilchard May 29 '21 at 10:36
  • @pilchard Yes, I need to make sure that the application starts – CodeG May 29 '21 at 10:38

1 Answers1

0

The problem here seems to be that you are not returning anything in the catch block which eslint is expecting. Please add some return in the catch block and check in the function whether it's your remote instance or not and act accordingly.