Axe*_*xel 2 typescript reactjs recoiljs
我是 Recoil 的新手,现在遇到了问题。问题是我希望能够将原子默认值定义为未定义,因为我必须在开始时进行一些异步调用和更多操作来设置它,有时它可能是未定义的,直到我得到一些用户输入。所以我试图将原子定义为:
export const locationState: RecoilState<LocationInterface | undefined> = atom({
key: "location",
default: undefined,
});
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:“类型‘RecoilState’不可分配给类型‘RecoilState<LocationInterface | undefined>’。”
在我使用反冲值的其他地方,一切都正常,但我仅在原子文件中收到上述错误。
有没有办法做我正在做的事情,或者我是否试图用 Recoil 做一些根本错误的事情?
提前致谢!
我解决了!正确的语法是:
export const locationState = atom<LocationInterface | undefined>({
key: "location",
default: undefined,
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3412 次 |
| 最近记录: |