【问题标题】:reset recoil state to default not working将反冲状态重置为默认值不起作用
【发布时间】:2021-11-04 11:21:16
【问题描述】:

尝试使用useResetRecoilState将反冲状态重置为其默认值,但不起作用 这是我的代码

import {filter} from '..appl/recoil/atoms';
import { useResetRecoilState } from 'recoil';
let filterReset = () => { useResetRecoilState(filter); }
.
.
onSignOut = () => { 
/*Code for signout and other stuff*/
filterReset();
 } 

反冲状态码为:

import { atom, useRecoilState } from 'recoil';
export const filter = atom({
  key: 'filter',
  default: {
    handlers: [],
    product: '',
    origin: '',
    destination: ''
}
}

使用了这个documentation,但没有帮助

【问题讨论】:

    标签: javascript reactjs react-native recoiljs


    【解决方案1】:

    useResetRecoilState 返回一个重置反冲状态的函数。应该这样使用:

    import {filter} from '..appl/recoil/atoms';
    import { useResetRecoilState } from 'recoil';
    
    onSignOut = () => { 
        const filterReset = useResetRecoilState(filter);
        /*Code for signout and other stuff*/
        filterReset();
    } 
    

    【讨论】:

    • 试过了.....但是没有效果
    猜你喜欢
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    相关资源
    最近更新 更多