我在我的项目中使用 react-select 2。每次用户选择一个选项时,输入值都会被清除,这会导致选项列表发生变化。
有没有办法保留输入值以便用户可以选择多个选项?这是我尝试过的:
<Select
closeMenuOnSelect={false}
blurInputOnSelect={false}
isMulti
loadOptions={this.resultProvider.bind(this)}
inputValue={this.state.searchKey}
onInputChange={this.handleInputChanged.bind(this)}
/>
Run Code Online (Sandbox Code Playgroud)
handleInputChanged(input, reason) {
if (reason.action === "set-value") {
return;
}
this.setState({
...this.state,
searchKey: input
});
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个演示来演示这个问题:https : //codesandbox.io/s/345rp0m041
请注意,此问题仅发生在异步选择中。
感谢您的建议!
我正在开发一个使用 react-history 的应用程序。每次我使用以下方法更改 URL 时,整个应用程序都会重新呈现:
props.history.location.replace(newPath);
Run Code Online (Sandbox Code Playgroud)
这种行为对性能有很大的影响。
我想要的只是更改更新一些查询参数的 URL,以便用户可以仅通过 url 与另一个共享视图。
我想知道是否有办法解决这个问题。
谢谢你的建议。