Material-UI InputBase 구성 요소 내에서 InputComponent로 react-select Select 구성 요소를 통과하고 있습니다. 옵션에서 값을 성공적으로 채울 수 있었지만 사용할 수 없습니다 isClearable
.
isClearable이 트리거되면 null이 handleChange(event)
함수에 전달되며 null이 오류를 생성하지 않도록 개체를 강제로 통과시키는 방법이 있기를 바랍니다.
InputBase 내의 handleChange 함수에는 var element = event.target || inputRef.current
. 이벤트가 null이므로 필요한 객체를 포함 할 inputRef에 도달하지도 않습니다.
제어되지 않는 구성 요소로 작동하는 것이 좋을 것입니다.
문제를 설명하기 위해 코드 상자를 만들었습니다. https://codesandbox.io/s/morning-feather-l7xqf
사용자 정의 onChange()
를 제공 null
하여 자신의 가치 를 포착 하고 전달할 수 있습니다.
// Deconstruct from otherProps
const SelectWrapper = ({ inputRef, onChange, ...otherProps }) => {
function handleChange(event) {
// Overwrite the event with your own object if it doesn't exist
if (!event) {
event = {
target: inputRef,
value: '',
};
}
onChange(event);
}
return (
// Pass in the custom handleChange
<Select styles={customStyle} isClearable ref={inputRef} onChange={handleChange} {...otherProps} />
);
};
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다