UNPKG

xph-form

Version:

This is a configurable form component that supports React

32 lines (31 loc) 1.23 kB
import { jsx as _jsx } from "react/jsx-runtime"; import React from "react"; import { Select } from "antd"; import { useApiComonentCache } from "../../hooks"; const ApiSelect = (apiSelectProps) => { console.log("render ApiSelect"); const { api, params, immediate = true, isusewatch, onDropdownVisibleChange: onDropdownVisibleChangeProp, } = apiSelectProps; const isUseWatch = isusewatch === "true"; const [options, setOptions] = React.useState([]); const { getApiData: getApiOptions } = useApiComonentCache({ api, immediate, params, apiCallback: setOptions, isUseWatch, }); const onDropdownVisibleChange = (visible) => { if (visible) { /** 目前每次展开都会请求 */ !immediate && getApiOptions(); } onDropdownVisibleChangeProp && onDropdownVisibleChangeProp(visible); }; /** 把扩展的属性排除掉 */ const getSelectProps = () => { const { api, params, immediate, isusewatch, ...rest } = apiSelectProps; return rest; }; return (_jsx(Select, { ...getSelectProps(), options: options, onDropdownVisibleChange: onDropdownVisibleChange })); }; export default ApiSelect;