简体   繁体   中英

ReactJS with typescript

i creating a form with React-selec. When i do a function and pass parameters he returns me
Expected 1 arguments, but got 0.ts(2554) index.tsx(31, 31): An argument for 'selectRef' was not provided.

 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])

The function parseSelectValue expects a selectRef; Its a non-optional parameter.

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

Paste this should fix the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM