簡體   English   中英

帶有打字稿的 ReactJS

[英]ReactJS with typescript

我用 React-selec 創建了一個表單。 當我執行函數並傳遞參數時,他返回我
預期 1 個參數,但得到 0.ts(2554) index.tsx(31, 31):未提供“selectRef”的參數。

 useEffect(() => { function parseSelectValue(selectRef: { state: { value: any } }) { const selectValue = selectRef.state.value if (!multiple) { return selectValue ? selectValue.id : '' } return selectValue ? selectValue.map((option: { id: any }) => option.id) : [] } registerField({ name: fieldName, ref: ref.current as any, path: 'state.value', parseValue: parseSelectValue, clearValue: (selectRef: { select: { clearValue: () => void } }) => { selectRef.select.clearValue() } }) parseSelectValue() }, [fieldName, registerField, multiple])

函數 parseSelectValue 需要一個 selectRef; 它是一個非可選參數。

    function parseSelectValue(selectRef?: { state: { value: any } }) {
        const selectValue = selectRef ? selectRef.state.value : undefined;

粘貼這個應該可以解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM