tiny-atom
tiny-atom copied to clipboard
memoized selectors
Hello, is this library able to do memoized selectors aka reselect? If yes how should it be used the "tiny-atom way" ?
Create and export your selectors, e.g.:
import { createSelector } from 'reselect'
const getNotes = state => state.notes
const getTags = state => state.tags
export const notesWithTags = createSelector(
[getNotes, getTags],
(notes, tags) => notes.map(enhance(tags))
)
Then use them when mapping state in your components:
import { useAtom } from 'tiny-atom/react/hooks'
import { notesWithTags } from './selectors'
export function Notes () {
let { notes } = useAtom(state => ({
notes: notesWithTags(state)
}))
return <List notes={notes} />
}
Now component will only rerender if the selector returns different value. And the selector will only be recomputed if notes or tags in the state change.