Recoil简介--安装教程

NPM

The Recoil package lives in npm. To install the latest stable version, run the following command:
Recoil包已经发不到npm,可以通过下列命令安装最新的最稳定的版本:

1
npm install recoil

或者是用yarn

1
yarn add recoil

Bundler

Recoil installed via NPM pairs nicely with module bundlers such as Webpack or Rollup.
就像webpack或者Rollup一样,Recoil可以搭配模块坏bundlers通过npm安装。

ES5 support ES5支持

Recoil builds are not transpiled to ES5, and we do not support the use of Recoil with ES5. If you need to support browsers that do not provide ES6 features natively, you can do so by compiling your code with Babel and using preset @babel/preset-env. However, we do not support this and you may run into problems.
Recoil的构建不能转化支持ES5,所以我们并不建议使用ES5。如果你需要兼容不支持ES6的本地浏览器。你也可以通过安装@babel/preset-env插件的方式通过babel转译来实现,但是我们并不支持这么做,这可能会出现问题。

In particular, just like React, Recoil depends on the Map and Set types and other features of ES6. Emulation of these features using polyfills may result in far worse performance.
就像React一样,Recoil依赖于Map或者Set类型的ES6语法,但是如果通过使用polyfills来达到这一目的也许会得到事倍功半的效果。

CDN

Since version 0.0.11, Recoil offers a UMD build that can be directly used in a <script> tag and exposes the symbol Recoil to the global namespace. We recommend linking to a specific version number and build to avoid unexpected breakage from newer versions:
从0.0.11版本开始,Recoil提供了UMD的构建方式,可以直接使用<script>标签,将Recoil暴露到全局。我们推荐引入一个具体版本,以免被收到新版本的影响。

1
<script src="https://cdn.jsdelivr.net/npm/recoil@0.0.11/umd/recoil.production.js"></script>

You can browse all Recoil files on the CDN at jsdelivr.
可以 通过CDN下载所有有关Recoil的资料

ESLint

If you are using eslint-plugin-react-hooks in your project. For example, with an eslint config like this:
如果你在你的项目里使用了eslint-plugin-react-hooks插件,例如,eslint的配置是这样:

1
2
3
4
5
6
7
8
9
10
// previous .eslint config
{
"plugins": [
"react-hooks"
],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
}
}

It is recommended to add ‘useRecoilCallback’ to the list of additionalHooks. With this change, ESLint will warn when the dependencies passed to useRecoilCallback() are specified incorrectly and suggests a fix. The format of additionalHooks is a regex string.
推荐在运用hooks的列表中添加useRecoilCallback,有了这个操作,eslint就会在有参数传入useRecoilCallback()函数后执行检查是否正确,并提示修复。hooks的格式是一个正则表达式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// modified .eslint config
{
"plugins": [
"react-hooks"
],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": [
"warn", {
"additionalHooks": "useRecoilCallback"
}
]
}
}

Nightly Builds Nightly构建

We build a package once every day based on the current master branch and publish it as the nightly branch on GitHub. You can use this branch via npm:
我们每天会依赖最新的master分支构建一次,并且以nightly分支发布到Github上,可以通过这个分支使用npm安装:

1
npm install https://github.com/facebookexperimental/Recoil.git#nightly

yarn:

1
yarn add https://github.com/facebookexperimental/Recoil.git#nightly

or add a dependency in package.json and run npm install or yarn:

或者是在package.json中添加依赖,并且通过命令npm install 或者yarn安装:

1
"recoil": "facebookexperimental/Recoil.git#nightly",
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2015-2022 Lee
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信