Select
Generate, sort, select and label content in dropdowns or lists.
<Select>
Server Component
A smart dropdown component that creates all of its own options.
Live Example
useSelect
hook
useSelect
is a utility hook that lets you generate options for custom dropdown components or any list type content.
Live Example
Custom Server Component with getSelect
Setup
Add select: handleSelectRequest()
to the API route handler.
API Reference
Types
SelectOptions
Select API route handler options.Properties
openAiApiKeystring
- default`process.env.OPENAI_API_KEY`.
SelectRequestBodyinterface
Select request body.Properties
promptstring
A text description for creating the dropdown.- example'All the GMT time zones'
purposestring
A text description of the purpose of the dropdown.- example'Selecting your time zone'
contextstring
A text description of additional context or information to help create the dropdown.- example'The time zone for Sydney should be selected'
countnumber
The number of dropdown options or list items to create.- example10
SelectResponseinterface
Select response body.Properties
contentarray
An array of options to list or display in a dropdown.- example[{ label: 'GMT+10:00 Brisbane, Melbourne, Sydney', value: 'Australia/Sydney', selected: true }, { label: 'GMT+12:00 Auckland, Wellington', value: 'Pacific/Auckland' }, ...]
labelstring
The overall associated label for the dropdown.- example'Select Time Zone (GMT)'
ChatGptCompletionResponse
The response body for `getSelect`.Properties
responseTextstring
The response text extracted from the completion message content.tokensUsednumber
Total number of tokens used in the request (prompt + completion).finishReasonstring
The reason the chat stopped. This will be `stop` if the model hit a natural stop point or a provided stop sequence, `length` if the maximum number of tokens specified in the request was reached, `content_filter` if content was omitted due to a flag from our content filters, `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.errorMessagestring
The error message if there was an error.Components
SelectPropsinterface<object>
Props to pass to the `<Select>` Server Component.Properties
promptstring
A text description for creating the dropdown.- example'All the GMT time zones'
purposestring
A text description of the purpose of the dropdown.- example'Selecting your time zone'
contextstring
A text description of additional context or information to help create the dropdown.- example'The time zone for Sydney should be selected'
countnumber
The number of dropdown options or list items to create.- example10
labelReactNode
Visible text in the `<label>` element. Overrides any generated `label` from the response.labelPropsHTMLAttributes<object>
Additional props to pass to the `<label>` element.Selectfunction
Select is a smart Server Component for dropdowns that creates, labels and sorts all its own options. Uses a native `<select>` element.Parameters
propsSelectPropsrequired
- linkSelectProps
Hooks
useSelectfunction
A client-side fetch handler hook for generating a `label` and a list of options in `content` based on the provided `SelectRequestBody`.Parameters
bodySelectRequestBodyrequired
configUseRequestConsumerConfig<SelectRequestBody>
Fetch utility hook request options without the `fetcher`. Allows for overriding the default `request` config.Returns
isLoadingboolean
Fetch loading state. `true` if the fetch is in progress.isErrorboolean
Fetch error state. `true` if an error occurred.errorunknown
Fetch error object if `isError` is `true`dataSelectResponse | undefined
Fetch response data if the fetch was successful.refetchfunction
Refetches the data.Utilities
getSelectfunction
Generates a list of options to list or display in a dropdown. Server Action that calls the third-party API directly on the server. This avoids calling the Next.js API route handler allowing for performant Server Components.Parameters
requestSelectRequestBodyrequired
optionsSelectOptions
- linkSelectOptions
fetchSelectfunction
Generates a `label` and a list of options in `content` based on the provided `SelectRequestBody`. Client-side fetch handler that calls the internal Next.js API route handler, then the third-party API. Best used for Client Components and functionality.Parameters
bodySelectRequestBodyrequired
configRequestConfigOnly
Fetch utility request options without the `body`