Created
October 12, 2022 12:08
-
-
Save ksimons/8512d59d41a634a1c231e6116d5c4d29 to your computer and use it in GitHub Desktop.
Recoil fine-grained selectors
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
const workItemTitleSelector = selectorFamily({ | |
key: 'WorkItemTitle', | |
get: | |
(workItemId: string | undefined | null) => | |
({ get }) => { | |
return get(workItems(workItemId)?.title; | |
}, | |
}); | |
// only fetch what we need! | |
function WorkItemCard({ workItemId }: { workItemId: string }) { | |
const workItemTitle = useRecoilValue(workItemTitleSelector(workItemId)); | |
return ( | |
<div> | |
{workItemTitle} | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment