假设代码如下: this.props.myFunction(); EsLint给出以下错误: Must use destructuring props assignment react/destructuring-assignment 虽然当前的代码是清晰和简洁的,但如果我仍然想要分解代码并让EsLint满意,我该怎么做呢?
我在react中遇到了一些eslint的问题。它要求我使用解构属性赋值,但当我更改代码时,它就会崩溃。
有什么想法吗?
这是完整的代码
class LoginPage extends React.Component {
submit = data =>
// This is how I tried to fix it!
// {
// const { login, history } = this.props;
// login(data).then(() => history.push('/'));
// };
class MyDrawer extends Component {
const modalOpen = this.state;
render() {
return (
<div>
<Drawer
modal
open={this.state.modalOpen} // <-- this line show error [eslint] Must use destructuring state assignment (react/destructuring-assignment)
在我的React应用中,我使用的是airbnb的eslint风格指南,如果我不使用destructuing,它会抛出一个错误。
在下面的情况中,我首先使用let将两个变量latitude和longitude赋给location对象数组中第一个项目的坐标。然后,如果用户允许我访问它们的位置,我会尝试使用解构来重新分配它们的值。
let latitude = locations[0].coordinates[1];
let longitude = locations[0].coordinates[0];
if (props.userLocation.coords) {
// doesn
谢谢您抽时间见我。 新手反应问题...我知道componentDidMount会在第一次呈现组件后触发,这就是为什么我收到的prop-types eslint错误会被触发的原因。但是,我不确定您将如何修复此问题并添加验证,因为propTypes验证在getArticles()函数之前触发,因此如果我声明一个propTypes,它将返回未定义的...例如,直到第一次渲染和componentDidMount被调用之后,项目才被定义...有很好的挖掘,不能看到一个简单的解决方案,我认为是一个常见的问题?? 问题-如何验证尚未获取的道具。 class ArticlesList extends Com
我想在Typescript GraphQL中使用解构。很多API函数都使用data作为第一级键。如何才能在不出现Typescript/TSLint错误的情况下执行以下操作。更改为var将导致它希望成为let,即Cannot redeclare block-scoped variable & block-scoped used before its declaration。当然,const是一个错误。移除第二个let将不允许我分解第二个data。 let {data}:OverlayEventDetail = await modal.onDidDismiss();
if (data.s
我正在用Karma,为我的角度应用程序编写单元测试,我运行我的代码库。
我定义了将在beforeEach inject中使用的全局变量来创建sinon.stub。ESLint一直抱怨我的全局变量是定义的,但从未使用过。例如:
'getListStub' is defined but never used no-unused-vars
但在我的代码中它看起来是这样的
var listService, getListStub;
beforeEach(inject(function(_listService_) {
listService = _listService_;
我这里有个密码:
getData(value, index) {
const {responseMetadata, responseData} = this.getResponseDatum();
return responseData.get(index).get('code').toUpperCase();
}
eslint报告了一个错误:
19:12 "responseMetadata" is defined but never used
在python中,我可以通过将变量重命名为_responseMetadata来避免这种
在下面的示例中,在函数Test()中,第一行编译成功,而第二行没有编译,尽管我有一个KeyValuePair的Deconstruct扩展方法。为什么会这样呢?
public static class Tests {
class Foo { }
class Bar { }
public static void Test() {
// This works:
Bar[] works = new List<ValueTuple<Foo, Bar>>()
.Select(((Foo foo, B
我相信这是显而易见的,但我不明白为什么现在不能工作……
我在Vue项目中有一个文件,它以两种不同的格式导出键码,一种用于常量(allCodes),另一种用于Vue (keyCodes):
export default {
allCodes,
keyCodes
};
当我尝试像这样使用解构来导入其中的一个时,我得到了一个错误:
import { allCodes } from '@/helpers/keycodes';
21:17-25 "export 'allCodes' was not found in '@/helpers/keyco
我正在寻找一种在解构对象时操作数据的智能方法。看一下下面的代码: let employee = {
name: 'John Doe',
birthday: '1980/01/01', // yyyy/MM/dd format
department: 'R&D'
}
const { name, birthday, department } = employee
console.log(`${name} is working under ${department} and their birthday is on $
我有Person类
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public void Deconstruct(out int id) { id = Id; }
}
当我试图用以下代码解构它时:
var (id) = new Person();
编译器说:
无法推断隐式解构变量'id‘的类型。
当有多个参数时,编译器不会这么说。如下所示:
public void Deconstruct(out int id, out string n
我在客户端使用TypeScript,当我运行应用程序时,有两个错误显示如下:
@typescript-eslint/no-unsafe-assignment: Unsafe assignment of an `any` value.
@typescript-eslint/no-unsafe-member-access: Unsafe member access .value on an `any` value.
这是我的代码:
const userInfo = ref({} as UserInfo) // first error
$f.axios
.get<UserInfo&
我已经定义了一个如下的函数。
export default const myFunc = () => {
// Do stuff
}
然而,ESLint抱怨与Parsing Error: Only expressions, functions or classes are allowed as the default export的常量
有趣的是,如果我删除default关键字,ESLint也不会有任何抱怨。
为什么解析函数失败?