vrooom
vrooom

Reputation: 51

reset recoil state to default not working

tried to reset recoil state to its default value using useResetRecoilStatebut not working This is my code

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

recoil state code is :

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

used this documentation but didn't help

Upvotes: 0

Views: 3952

Answers (1)

Plargato
Plargato

Reputation: 555

useResetRecoilState returns a function that resets the recoil state. It should be used like this:

import {filter} from '..appl/recoil/atoms';
import { useResetRecoilState } from 'recoil';

onSignOut = () => { 
    const filterReset = useResetRecoilState(filter);
    /*Code for signout and other stuff*/
    filterReset();
} 

Upvotes: 2

Related Questions