[英]How to integrate recoil library with react-native?
I'm trying the new state management library from facebook recoil , I tried the Getting started example on a reactjs project and it worked perfectly.我正在尝试来自 facebook后坐力的新 state 管理库,我在 reactjs 项目上尝试了入门示例,它运行良好。 After that I tried recoil on a react-native project but I got an error:
之后,我在 react-native 项目上尝试了反冲,但出现错误:
Here's the code I've tried:这是我尝试过的代码:
App.js应用程序.js
import React from 'react';
import {RecoilRoot} from 'recoil';
import RecoilTest from './RecoilTest';
const App = () => {
return (
<RecoilRoot>
<RecoilTest />
</RecoilRoot>
);
};
export default App;
RecoilTest.js RecoilTest.js
import React from 'react';
import {useRecoilState} from 'recoil';
import {View, Text} from 'react-native';
import {textState} from './Atoms';
const RecoilTest = () => {
const [text, setText] = useRecoilState(textState);
return (
<View>
<Text>{text}</Text>
</View>
);
};
export default RecoilTest;
Atoms.js原子.js
import {atom} from 'recoil';
export const textState = atom({
key: 'textState',
default: 'initial value',
});
Recoil don't has a fully support to react native yet Recoil 还没有完全支持原生反应
Towards release走向释放
Hi everyone.
大家好。 FYI we've published a "nightly build" branch for testing purposes, If you want to try out recoil with react native before we release next version: try install the nightly branch with the "install git branch" feature of npm/yarn:
仅供参考,我们已经发布了一个“夜间构建”分支用于测试目的,如果您想在我们发布下一个版本之前尝试使用 react native 进行反冲:尝试使用 npm/yarn 的“安装 git 分支”功能安装夜间分支:
npm install https://github.com/facebookexperimental/Recoil.git#nightly
Or
yarn add https://github.com/facebookexperimental/Recoil.git#nightly
或
yarn add https://github.com/facebookexperimental/Recoil.git#nightly
Update: RN support is now there in Recoil.js as Experimental.更新:现在 Recoil.js 中的 RN 支持是实验性的。
https://github.com/facebookexperimental/Recoil/releases/tag/0.1.1 https://github.com/facebookexperimental/Recoil/releases/tag/0.1.1
Try using 'useRecoilValue' instead in your RecoilTest.js file尝试在 RecoilTest.js 文件中使用“useRecoilValue”
const [text, setText] = useRecoilValue(textState);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.