solid-primitives
solid-primitives copied to clipboard
Add selectors
Using createSelector
is good for a single values. I found that there are a lot of use cases for array selectors. I have been using this on a few projects and I think it would be a good addition to the library.
const list: string[] = ["apple", "pear", "orange"]
const [selectedItems] = createSignal<string[]>(["apple"])
const isSelected = createArraySelector(selectedItems)
<For each={list}>
{(item) => <li classList={{ active: isSelected(item) }}>{item}</li>}
</For>
Extending with a comparator function (instead of b.includes(a)
) to support objects could be possible, but I decided to keep it simple. At that point it might be better to just create a custom selector directly.