简体   繁体   English

eslint:围绕箭头主体的意外块语句

[英]eslint: Unexpected block statement surrounding arrow body

I have a component in react and I am getting an error lint:我有一个反应组件,我收到一个错误 lint:

Unexpected block statement surrounding arrow body;箭头主体周围出现意外的块语句; move the returned value immediately after the => arrow-body-style=> arrow-body-style 之后立即移动返回值

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

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

Which return should I remove?我应该删除哪个退货? I didn't quite understand the explanation.我不太明白解释。 Thanks!谢谢!

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

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

You are writing an arrow function body that just immediately returns:您正在编写一个箭头 function 正文,该正文立即返回:

 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 }} />;
  }
}

if there is only one return in the statement, we should remove the return like the following example.如果语句中只有一个return ,我们应该像下面的例子一样去掉return

res => {
    return new Promise().resolve(null);
}

Should be in this way应该是这样

res => (new Promise().resolve(null)); 

To your case, it should be like the following对于您的情况,它应该如下所示

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM