import { ReactNode } from 'react'
import { YMaps } from 'react-yandex-maps'
type OnChange = (value: string) => void
export interface SuggestViewProps {
children?: ReactNode
onClick?: () => void
}
export interface SuggestProps {
color?: string
disabled?: boolean
id?: string
readOnly?: boolean
placeholder?: string
value?: string
ymaps?: typeof YMaps
onChange?: OnChange
onSuggest?: OnChange
}
type OnUpdateCallback = (value: string) => Promise<boolean>
export type Update = (
ymaps: typeof YMaps,
setItems: (items: any[]) => void,
) => OnUpdateCallback
export type Change = (
value: string,
onUpdate: OnUpdateCallback,
onChange: OnChange,
) => void
export type Select = (
value: string,
onSuggest: OnChange,
onUpdate: OnUpdateCallback,
onChange: OnChange,
setToggle: (toggle: boolean) => void,
) => void
import { Change, Select, Update } from './types'
export const update: Update = (ymaps, setItems) => async value => {
const options = {
results: 6,
}
if (!ymaps.suggest) {
return false
}
const items = await ymaps.suggest(value, options)
setItems(items)
return true
}
export const change: Change = (value, onUpdate, onChange) => {
onUpdate(value)
onChange(value)
}
export const select: Select = (
value,
onSuggest,
onUpdate,
onChange,
setToggle,
) => {
onUpdate(value)
onSuggest(value)
onChange(value)
setToggle(false)
}
https://discord.com/developers/docs/resources/chan...