Skip to main content

Interface: UseFrecencyReturn<T>

Defined in: use-frecency.ts:68

Value returned by useFrecency.

Type Parameters​

T​

T extends string | number

The type of the item ids.

Properties​

clear​

clear: () => void

Defined in: use-frecency.ts:96

Forgets every item. Stable identity.

Returns​

void


rank​

rank: (ids) => T[]

Defined in: use-frecency.ts:84

Returns a sorted copy of ids, highest score first. Items that were never recorded come last, and items with equal scores (including those never recorded) keep their order from ids. It does not change ids and does not add or remove anything.

It has a new identity whenever the scores change, so it works as a useMemo dependency.

Parameters​

ids​

readonly T[]

Returns​

T[]


record​

record: (id) => void

Defined in: use-frecency.ts:74

Counts one use of id now: its score becomes its current (decayed) score plus one. Call it when the user picks, opens or runs an item. Stable identity.

Parameters​

id​

T

Returns​

void


remove​

remove: (id) => void

Defined in: use-frecency.ts:94

Forgets id. Nothing happens when it was never recorded. Stable identity.

Parameters​

id​

T

Returns​

void


score​

score: (id) => number

Defined in: use-frecency.ts:92

Returns the current score of id, or 0 when it was never recorded (or was removed or evicted). The value shrinks as time passes, so it is only meaningful next to other scores read at about the same time.

It has a new identity whenever the scores change.

Parameters​

id​

T

Returns​

number