我想了解关于useEffect和eslint的3种“为什么”,以及关于useEffect如何定义何时触发的总体“如何”。
问题以注释形式出现在代码示例中。
。
import React, { useEffect, useState, useCallback } from "react";
import ReactDOM from "react-dom";
function App() {
// Case A
// why eslint want a as dependensy if it works fine?
const [a, setA] =
我有一个TypeScript项目正在利用ESLint。我有一个类,它使用作为类属性。我希望能够将缓冲区设置为构建的一部分。
example.ts
export class Example {
public myBuffer: Buffer
public constructor(myBuffer: Buffer) {
this.myBuffer = myBuffer
}
}
此块将产生以下链接错误:
5:3 error Unsafe assignment of an `any` value @typescript-eslint/n
在useEffect的依赖数组中定义setState值的想法是什么?
const [someState, setSomeState] = useState();
...
useEffect(() => {
// Do something
setSomeState('some value');
}, [setSomeState]);
React Hook useEffect has a missing dependency: 'setSomeState'.
Either include it or remove the dependency arra
假设您正在使用React,并且您正在编写一个自定义钩子useSomething,它在每次为同一个组件调用相同的东西时返回相同的东西。
const something = useSomething()
// useSomething() at time X === useSomething() at time Y
如果您现在在一个something中使用这个useEffect(() => ...)值,并且不将something作为依赖项传递给useEffect的第二个参数的数组,那么linter将警告您:
React缺少一个依赖项:“missing”。要么包含它,要么删除依赖数组。(
我正在使用create app+ typescript + eslint应用程序,在构建过程中有这样的错误:
Line 1:8: 'React' was used before it was defined @typescript-eslint/no-use-before-define
组件中的代码以以下代码开头:
import React from "react";
Eslint设置:
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
我有一个js模块,并将其导入主js应用程序。
js模块有自己的功能/方法。
然而,当我试图从主js应用程序调用该方法时,我得到了eslint错误:
'testMethod' is defined but never used
test.js:
export default function test() {
console.log('foo');
function testMethod() {
console.log('bar');
}
}
app.js
import test from './test';
我试图让tinymce和eslint在vue应用程序中协同工作,但每次我尝试使用像tinymce.activeEditor...这样的东西时,eslint在构建时都会抛出错误'tinymce' is not defined。如果我禁用eslint,应用程序可以很好地构建,并且我可以正常使用tinymce.activeEditor...。既然tinymce是从云中获取的,我如何在应用程序中定义它,以避免eslint抛出错误?
我想在我用Cypress测试的React应用程序中使用Flow,我使用带有流预置的web预处理程序。首先,我在./cypress/plugin/index.js中编写了预处理程序:
const webpack = require('@cypress/webpack-preprocessor')
module.exports = (on) => {
const options = {
// send in the options from your webpack.config.js, so it works the same
// as your a
我在将它们添加到一些现有的项目时遇到了一些困难。例如,我在我开发的模块中有一个类:
export default class ClassName {
// Class members
}
现在,我将它导入另一个项目:
import ClassName from 'modulename';
const object = new ClassName();
我在这条线上有两个错误。
论object in const object
error Unsafe assignment of an any value @typescript-eslint/
我正在开发一个应用程序,它使用VueJS显示视图,ExpressJS作为服务器。
到目前为止,在本地运行良好,但是在Heroku上成功地部署它之后,它没有加载应用程序并使dyno崩溃。
我的文件夹结构是这样的:
项目根
客户端
客户端package.json
- server
- package.json for server
- package.json that tells Heroku to install dependences in both folders
这是Heroku所指的构建整个应用程序的package.json:
{