eslint

不要再滥用useMemo了!你应该重新思考Hooks memoization

孤者浪人 提交于 2020-12-19 09:55:34
不要再滥用useMemo了!你应该重新思考Hooks memoization 作者 | Ohans Emmanuel译者 | 王强编辑 | Yonie 在使用 React Hooks 的过程中,作者发现过渡频繁的应用 useMemo 用会影响程序的性能。在本文中作者将与大家分享如何避免过度使用 useMemo,使程序远离性能问题。 经过观察总结,我发现在两种情况下 useMemo 要么没什么用,要么就是用得太多了,而且可能会影响应用程序的性能表现。 第一种情况很容易就能推断出来,但是第二种情况就比较隐蔽了,很容易被忽略。如果你在生产环境的应用程序中使用了 Hook,那么你就可能会在这两个场景中使用 useMemo Hook。 下面我就会谈一谈为什么这些 useMemo 没什么必要,甚至可能影响你的应用性能。此外我会教大家在这些场景中避免过度使用 useMemo 的方法。 我们开始吧。 不需要 useMemo 的情况 为了方便,我们把这两类场景分别称为狮子和变色龙。 先不用纠结为什么这么叫,继续读下去就是。 当你撞上一头雄狮,你的第一反应就是撒丫子跑,不要成为狮子的盘中餐,然后活下来跟别人吹牛。这时候可没空思考那么多。 这就是场景 A。它们是狮子,你应该下意识地躲开它们。 但在谈论它们之前,我们先来看看更隐蔽的变色龙场景。 相同的引用和开销不大的操作 参考下面的示例组件: /**

vue项目报eslint格式错误解决方案

故事扮演 提交于 2020-12-18 06:53:07
Vue Vue-cli Eslint 在vscode里代码自动格式化 HuaRongSAO 关注 2017.10.19 11:28* 字数 189 阅读 10396 评论 5 喜欢 12 vue eslint 代码自动格式化 vue-cli 代码风格为 JavaScript Standard Style 代码检查规范严格,一不小心就无法运行,使用eslint的autoFixOnSave可以在保存代码的时候自动格式化代码 VSCode拓展插件推荐(HTML、Node、Vue、React开发均适用) 建议阅读: vscode插件推荐 JavaScript Standard Style 代码风格规范 正文 eslint 自动格式化 配置环境: npm i -g eslint-plugin-vue #or npm i -S eslint-plugin-vue 创建项目跟路径下的文件:.eslintrc | .eslint.js // 添加插件 "plugins": [ "vue" ] 在你的vscode设置文件里添加: 1、在vscode添加 eslint 插件 2、在vscode添加 vetur 插件 3、修改你的setting.json // 添加进你的vscode的 setting.json "eslint.autoFixOnSave": true, "eslint.validate

How to use ESLint TypeScript Airbnb configuration?

谁都会走 提交于 2020-12-15 06:50:56
问题 I try to install and use ESLint Airbnb configuration for TypeScript for several days and I cannot make it work. Can somebody give installation and configuration steps of a working configuration, please? Below is one of my attempts to lint this code base using Airbnb convention. Airbnb configuration doesn't support Typescript ESLint 3.0 yet, so I will install TypeScript ESLint 2.34. Typescript ESLint 2.34 doesn't support ESLint 7 yet, so I will install ESLint 6.x. Typescript ESLint 2.34 doesn

使用vue-cli搭建vue项目

白昼怎懂夜的黑 提交于 2020-12-12 01:29:59
1.安装node环境,然后在命令行输入node -v 和npm -v 查看版本号 2.在正式开始项目之前我们先介绍一下vue-cli,vue-cli是一个脚手架工具,vue-cli是帮助我们写好vue.js基础代码的工具,可以帮助我们生成一个项目目录,可以本地调试,单元测试,代码部署等等。 安装vue-cli $ npm install -g vue-cli 开始创建项目 使用vue-cli $ vue init <template-name> <project-name> 第一个是模板名称,第二个是项目名称,模板有webpack,webpack-simple ,browserify ,browserify-simple ,simple我们这个项目使用的是 webpack 。 下面我们就来搭建一个项目名称为myvue模板为webpack的vue项目(注:此处项目名不可有大写): vue init webpack myvue 接下拉终端里面会问你(也可能会跟你说vue不是内部或外部命令,本篇文章结尾会有解决办法) ? Project name (myvue) 项目名称是不是 myvue ,我们按回车,表示,是。当然,你也可以重写一个,然后回车。 然后 ? Project description (A Vue.js project) 项目描述,一个 vue.js 的项目。同样

How to fix unexpected token in ESLint?

你说的曾经没有我的故事 提交于 2020-12-08 06:58:38
问题 I install ESLint globally using the command npm install -g eslint on my Mac. It was successful installing, but when I run eslint -v this is the issue I encounter: $ npm install -g eslint path/to/bin/eslint -> path/to/lib/node_modules/eslint/bin/eslint.js + eslint@7.3.1 added 107 packages from 63 contributors in 4.823s $ eslint -v path/to/lib/node_modules/eslint/bin/eslint.js:93 } catch { ^ SyntaxError: Unexpected token { at createScript (vm.js:80:10) at Object.runInThisContext (vm.js:139:10)

Eslint - `Parsing error: unexpected token =` error for assigned fat arrow / property initializer

醉酒当歌 提交于 2020-12-08 06:23:42
问题 I'm using an arrow function and it's complaining about a parsing error: Parsing Error: Unexpected token = However my code is valid (please tell me if i'm mistaken). Additionally, i've set the .eslintrc settings to use es6 parsing: .eslintrc { "parserOptions": { "ecmaVersion": 6, } } Here's my code: class foo() { // Doesn't like the line below // even though it is valid: namedFunction = () => { } } There a way to resolve this error? This makes a huge different in terms of what the value of

Eslint - `Parsing error: unexpected token =` error for assigned fat arrow / property initializer

天涯浪子 提交于 2020-12-08 06:23:25
问题 I'm using an arrow function and it's complaining about a parsing error: Parsing Error: Unexpected token = However my code is valid (please tell me if i'm mistaken). Additionally, i've set the .eslintrc settings to use es6 parsing: .eslintrc { "parserOptions": { "ecmaVersion": 6, } } Here's my code: class foo() { // Doesn't like the line below // even though it is valid: namedFunction = () => { } } There a way to resolve this error? This makes a huge different in terms of what the value of

Eslint - `Parsing error: unexpected token =` error for assigned fat arrow / property initializer

一个人想着一个人 提交于 2020-12-08 06:22:38
问题 I'm using an arrow function and it's complaining about a parsing error: Parsing Error: Unexpected token = However my code is valid (please tell me if i'm mistaken). Additionally, i've set the .eslintrc settings to use es6 parsing: .eslintrc { "parserOptions": { "ecmaVersion": 6, } } Here's my code: class foo() { // Doesn't like the line below // even though it is valid: namedFunction = () => { } } There a way to resolve this error? This makes a huge different in terms of what the value of

How to upgrade the version of ESLint used in Visual Studio 2019?

折月煮酒 提交于 2020-12-06 03:48:36
问题 I am using ESLint with Visual Studio 2019. The integration works well, I can see the ESLint errors directly in the IDE. But when I add more rules to my config file, like no-async-promise-executor, I get errors like (ESLint) Definition for rule 'no-async-promise-executor' was not found C:\Work\GatewayServer\Multicheck.GW.Web (tsconfig or jsconfig project) It turns out that the ESLint version is a bit outdated. In C:\Users\username\AppData\Local\Microsoft\TypeScript\ESLint\package.json , we can

ESLint - no-unused-expressions in ReactJS

情到浓时终转凉″ 提交于 2020-12-05 12:17:05
问题 Getting a ESLint error when copiling with babel: Line 28: Expected an assignment or function call and instead saw an expression no-unused-expressions Line 29: Expected an assignment or function call and instead saw an expression no-unused-expressions Any idea how to get rid of these whilst making my timer still work as intended? Or have you got a better way of me doing my timer? class RequestTimer extends Component { constructor(props) { super(props); this.state = { seconds: 0, minutes: 0,