UNPKG

zmp-react

Version:

Build full featured iOS & Android apps using ZMP & React

28 lines (25 loc) 754 B
import { useEffect } from 'react'; import { zmpready, zmp } from './zmp'; import { extend } from './utils'; export var useSmartSelect = function useSmartSelect(smartSelect, smartSelectParams, zmpSmartSelect, getEl) { var onMount = function onMount() { zmpready(function () { if (smartSelect) { var ssParams = extend({ el: getEl() }, smartSelectParams || {}); zmpSmartSelect.current = zmp.smartSelect.create(ssParams); } }); }; var onDestroy = function onDestroy() { if (zmpSmartSelect.current && zmpSmartSelect.current.destroy) { zmpSmartSelect.current.destroy(); } zmpSmartSelect.current = null; }; useEffect(function () { onMount(); return onDestroy; }); };