[英]I am trying to Reast React-Select's AsyncSelect from a parent component (https://react-select.com/home)
I am trying to reset AsyncReact ( https://react-select.com/home ) from a parent component (Hooks) but I cant seem to get it to work.我正在尝试从父组件(Hooks)重置 AsyncReact( https://react-select.com/home ),但我似乎无法让它工作。 Any help much appreciated.
非常感谢任何帮助。
I can reset it from within the component by setting the state to an empty array but I cant seem to reset it from outside.我可以通过将状态设置为空数组来从组件内部重置它,但我似乎无法从外部重置它。
Parent Component父组件
const MessengerMessagesTwo = ({ props }) => {
const orgSearchRef = useRef(null);
const handleClearOrgSearch = () => {
orgSearchRef.current.clearValue();
}
return <div>
<button onClick={() => handleClearOrgSearch()}>clear</button>
<MessengerMessagesTwoOrgSearch ref={orgSearchRef} />
</div>
})
Child Component子组件
const MessengerMessagesTwoOrgSearch = forwardRef(({props}, ref) => {
const [inputValue, setInputValue] = useState([]);
useEffect(() => {
setInputValue([]);
return () => {
setInputValue([]); // reset orgs selected
handleOrgSelectedCallback([]);
}
}, [])
return <div>
<AsyncSelect
isClearable
defaultOptions
placeholder="Search Orgs"
loadOptions={loadOptions}
onInputChange={handleInputChange}
onChange={handleChange}
isMulti
noOptionsMessage={i => "Search..."}
ref={ref}
/>
</div>
})
const mapStateToProps = (state) => {
return {
};
};
const mapDispatchToProps = (dispatch) => {
return {
};
};
export default connect(mapStateToProps, mapDispatchToProps, null, {forwardRef: true})(MessengerMessagesTwoOrgSearch);
Seems to be working now.似乎现在正在工作。 Did not change anything, and I am very confused
什么都没有改变,我很困惑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.