1. 程式人生 > 其它 >react 專案中的報錯,警告總結

react 專案中的報錯,警告總結

1.Nested block is redundant no-lone-blocks

2.Unexpected string concatenation of literals no-useless-concat

拼接字串報錯 "Unexpected string concatenation"
錯誤原因:ESLint推薦用ES6方法來拼接字串,而不能使用加號。
解決辦法:拼接字串使用形如:
`字串字串字串${變數名}字串字串字串${返回字串的方法}字串字串`的寫法。

3.series not exists. Legend data should be same with series name or data name.

4.React Hook useEffect has a missing dependency: 'fetchBusinesses'. Either include it or remove the dependency array react-hooks/exhaustive-deps

這不是JS / React錯誤,而是eslint警告。

它告訴你鉤子依賴於函式fetchBusinesses,所以你應該把它作為依賴傳遞。

1.useEffect(() => {

  fetchBusinesses();
}, [fetchBusinesses]);

如果fetchBusinessess

在執行中沒有元件,那將不會真正改變任何事情,但警告將消失。

2.useEffect(() => { // other code ... // eslint-disable-next-line react-hooks/exhaustive-deps }, [])

參考文章:https://www.soinside.com/question/yyxQ6i8PKsVyaS3teSftxH

5.