Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我的选择组件不执行onChange(React.js)_Javascript_Reactjs - Fatal编程技术网

Javascript 我的选择组件不执行onChange(React.js)

Javascript 我的选择组件不执行onChange(React.js),javascript,reactjs,Javascript,Reactjs,我有一个React-Select组件React-Select.com,它默认执行onChange操作。我想做的是设置另一个操作与第一个操作一起执行 问题是:当我将一个函数传递给onChange时,它会覆盖另一个函数。我试图做一些更改,但没有成功,所以我将在这里显示没有更改的代码 我的组成部分: 我想如何使用它: 这是因为您正在将{…props}作为最后一个prop传递给Select组件。因此,来自props的onChange函数将覆盖您声明的函数。试试这个: option.value==fiel

我有一个React-Select组件React-Select.com,它默认执行onChange操作。我想做的是设置另一个操作与第一个操作一起执行

问题是:当我将一个函数传递给onChange时,它会覆盖另一个函数。我试图做一些更改,但没有成功,所以我将在这里显示没有更改的代码

我的组成部分:

我想如何使用它:


这是因为您正在将{…props}作为最后一个prop传递给Select组件。因此,来自props的onChange函数将覆盖您声明的函数。试试这个:

option.value==field.value : } />
function SelectInput(props: any) {
const [field, defaultValue, {setValue}] = useField(props.field);

const handleChange = (value: any) => {
    setValue(value.value);
};

const {options} = props;

return (
    <Select
        styles={styles}
        className="react-select-container"
        classNamePrefix="react-select"
        options={options}
        name={field.name}
        onChange={handleChange}
        value={
            options
                ? options.find(
                      (option: any) => option.value === field.value
                  )
                : ''
        }
        {...props}
    />
);
}
{
<Field // this comes from Formi
    name="type"
    component={SelectInput} // here I tell Formik to render my component, it works the same as rendering it directly
    placeholder=" "
    options={options}
    onChange={() => {MY_FUNCTION_HERE}} // I want to call this function and also the handleChange inside the component
/>
}