[英]How to pass props from parent to child using typescript and react?
i want to pass props from parent to child using react and typescript. i am not sure how to add it to type.我想使用 react 和 typescript 将道具从父母传递给孩子。我不确定如何将其添加到类型中。
below is my code,下面是我的代码,
function Parent () {
return (
<DateRangePicker
onDatesChange={onDatesChange}
focusedInput={focusedInput}
onFocusChange={onFocusChange}
/>
);
}
type Props = Omit<
DayPickerRangeControllerShape,
'numberOfMonths' | 'hideKeyboardShortcutsPanel' | 'noBorder'
>;
function DateRangePicker(props: Props) {
return (
<Wrapper>
<DayPickerRangeController
{...props}
numberOfMonths={2}
focusedInput={focusedInput} //this is not detected
onFocusChange={onFocusChange} //this is not detected
/>
</Wrapper>
);
}
how can i add the focusedInput and onFocusChange props to type Props.我如何添加 focusedInput 和 onFocusChange 道具来键入道具。 right now it gives me error.
现在它给了我错误。 cannot find name "focusedInput".
找不到名称“focusedInput”。 cannot find name "onFocusChange"
找不到名称“onFocusChange”
could someone help me with this.有人可以帮我解决这个问题吗? thanks.
谢谢。
...
interface IProps {
focusedInput: Function
onFocusChange: Function
}
type Props = Omit<
DayPickerRangeControllerShape,
'numberOfMonths' | 'hideKeyboardShortcutsPanel' | 'noBorder'
> & IProps;
function DateRangePicker(props: Props) {
const {focusedInput, onFocusChange} = props
return (
<Wrapper>
<DayPickerRangeController
{...props}
numberOfMonths={2}
focusedInput={focusedInput} //this is not detected
onFocusChange={onFocusChange} //this is not detected
/>
</Wrapper>
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.