import * as React from 'react' const { useEffect, useRef, useCallback } = React export const Dropdown = (props: React.HTMLProps) => { const dropdownRef = useRef() useEffect(() => { const { current } = dropdownRef if (current) { const $select = $(current) $select.niceSelect() // jquery trigger doesn't trigger native handlers, so we gotta do it ourselves. $select.on('change', ($event) => { // don't recurse!! if (!$event.originalEvent) { $event.target.dispatchEvent(new Event('change', { bubbles: true })) } }) } return () => { if (current) { const $select = $(current) $select.off('change') $select.niceSelect('destroy') } } }, [dropdownRef.current, props.value, props.children]) return