React-Select: "Cannot read property 'replace' of undefined" 当我输入 Select
React-Select: "Cannot read property 'replace' of undefined" when I type in the Select
我正在实施 React-Select 异步。根据他们的文档,我的代码是正确的。然而,一旦我输入内容,onInputChange 就会抛出错误 "Cannot read property 'replace' of undefined"each。如何解决这个问题?
const options=[
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' }
]
export default function App() {
const [query, setQuery] = useState('')
const handleInputChange = (str) => {
const inputValue = str.replace(/\W/g, '');
setQuery(inputValue);
return inputValue;
};
return (
<>
<AsyncSelect
cacheOptions
//loadOptions={loadOptions}
defaultOptions={options}
onInputChange={(e)=> handleInputChange(e.target.value)}
/>
</>
);
}
我正在实施 React-Select 异步。根据他们的文档,我的代码是正确的。然而,一旦我输入内容,onInputChange 就会抛出错误 "Cannot read property 'replace' of undefined"each。如何解决这个问题?
const options=[
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' }
]
export default function App() {
const [query, setQuery] = useState('')
const handleInputChange = (str) => {
const inputValue = str.replace(/\W/g, '');
setQuery(inputValue);
return inputValue;
};
return (
<>
<AsyncSelect
cacheOptions
//loadOptions={loadOptions}
defaultOptions={options}
onInputChange={(e)=> handleInputChange(e.target.value)}
/>
</>
);
}