Skip to content

Instantly share code, notes, and snippets.

@chetanraj
Created August 10, 2020 17:45
Show Gist options
  • Save chetanraj/59a03d5e26c7cbb3af74c2d006630f0a to your computer and use it in GitHub Desktop.
Save chetanraj/59a03d5e26c7cbb3af74c2d006630f0a to your computer and use it in GitHub Desktop.
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