Created
August 10, 2020 17:45
-
-
Save chetanraj/59a03d5e26c7cbb3af74c2d006630f0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {atom, selector, useRecoilValue} from 'recoil'; | |
const nameStateAtom = atom({ | |
key: 'nameStateAtom', | |
default: '' | |
}); | |
const nameStateSelector = selector({ | |
key: 'nameStateSelector', | |
get: ({get}) => get(nameStateAtom) | |
}); | |
function NameDisplay() { | |
const name = useRecoilValue(nameStateAtom); | |
const nameSelector = useRecoilValue(nameStateSelector); | |
return ( | |
<> | |
Name: {name} | |
<br /> | |
Name from selector: {nameSelector} | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment