Skip to content

Instantly share code, notes, and snippets.

@mike-pete
Created April 17, 2023 03:32
Show Gist options
  • Save mike-pete/58c803cd6a2ac1ed361ac82dd8621648 to your computer and use it in GitHub Desktop.
Save mike-pete/58c803cd6a2ac1ed361ac82dd8621648 to your computer and use it in GitHub Desktop.
const useRecords = () => {
const [record, setRecord] = useState<Record<string, string>>({
'record 1': 'foo',
'record 2': 'foo',
'record 3': 'bar',
})
return {
get uniqueRecords() {
const uniqueRecords = new Set(Object.values(record))
return [...uniqueRecords]
},
}
}
const DisplayRecords: React.FC = () => {
const { uniqueRecords } = useRecords()
return (
<>
{uniqueRecords.map((record) => (
<p key={record}>{record}</p>
))}
</>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment