Skip to content Skip to sidebar Skip to footer

Eslint: Unexpected Block Statement Surrounding Arrow Body

I have a component in react and I am getting an error lint: Unexpected block statement surrounding arrow body; move the returned value immediately after the => arrow-body-style

Solution 1:

export function dashConfig(config) =>
  Component =>
    props => {
      const { data, isLoaded, error } = useDashConfig({ ...config });

      return <Component {...props} remoteConfig={{ data, isLoaded, error }} />;
    };
  };
}

Solution 2:

You are writing an arrow function body that just immediately returns:

function foo() {
  console.log("hello");
  return () => {
    return () => {
      console.log("world");
    }
  }
}

// Is the same as below

function bar() {
  console.log("hello");
  return () => () => {
    console.log("world");
  }
};

foo()()();
bar()()();

This applies to your own code in the following:

export function dashConfig(config) {
  return (Component) => {
    return (props) => {
      const { data, isLoaded, error } = useDashConfig({ ...config });

      return <Component {...props} remoteConfig={{ data, isLoaded, error }} />;
    };
  };
}

// Is the same as this

export function dashConfig(config) {
  return (Component) => (props) => {
    const { data, isLoaded, error } = useDashConfig({ ...config });

    return <Component {...props} remoteConfig={{ data, isLoaded, error }} />;
  }
}

Post a Comment for "Eslint: Unexpected Block Statement Surrounding Arrow Body"