Skip to content

React

@selkit/react provides a <SelkitSelect> component and a useSelkit hook. State is bridged with useSyncExternalStore, so re-renders are driven by the core and stay tear-free.

Component

<SelkitSelect> is controlled via value + onChange:

jsx
import { useState } from 'react'
import { SelkitSelect } from '@selkit/react'
import '@selkit/themes/base.css'

const options = [
  { value: 'apple', label: 'Apple' },
  { value: 'banana', label: 'Banana' },
]

export function Example() {
  const [value, setValue] = useState(null)
  return (
    <SelkitSelect
      options={options}
      value={value}
      onChange={(next, payload) => setValue(next)}
      placeholder="Pick a fruit…"
    />
  )
}

onChange receives (value, payload) where payload is { selected, value }. When multiple is set, value is an array.

Props

PropTypeNotes
optionsSelkitItem<T>[]Flat options or groups.
valueSelkitValueControlled value.
onChange(value, payload) => void
multipleboolean
placeholderstring
searchablebooleanDefaults to true.
fuzzybooleanFuzzy subsequence matching.
minInputLengthnumberGate filtering/loading.
minResultsForSearchnumberHide the search box for short lists.
hideSelectedbooleanRemove chosen options from the list.
loadOptions(query, page) => PromiseAsync / paginated loading.
taggable / createTagTagging.
maxSelectionsnumber
virtualScroll / itemHeightVirtual scrolling.
dropdownParentHTMLElement | stringPortal the dropdown (createPortal) out of clipping ancestors.
clearableboolean
renderOption(option, meta) => ReactNodeCustom option rendering.
renderSelection(option, meta) => ReactNodeCustom selected tag / single-value content.
classPrefixstring

See the full list in the Config reference.

Custom option rendering

jsx
<SelkitSelect
  options={options}
  renderOption={(option, { active, selected }) => (
    <span className={selected ? 'is-selected' : undefined}>⭐ {option.label}</span>
  )}
/>

Custom selection rendering

Customize the displayed tag / single value (e.g. add an icon). The component keeps the tag wrapper and remove button; meta is { index, multiple }.

jsx
<SelkitSelect
  options={options}
  multiple
  renderSelection={(option) => (
    <span>🔖 {option.label}</span>
  )}
/>

Hook

For custom markup, use useSelkit:

jsx
import { useSelkit } from '@selkit/react'

function Custom() {
  const { controller, state } = useSelkit({ options })
  // state is the live core state via useSyncExternalStore
  return <div>{state.visibleOptions.length} options</div>
}

controller is the same object documented in the Controller reference.

Released under the MIT License.