reactjs - 如何使用打字稿将道具从父母传递给孩子并做出反应?
问题描述
我想使用反应和打字稿将道具从父母传递给孩子。我不知道如何将其添加到类型中。
下面是我的代码,
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>
);
}
如何将focusedInput 和onFocusChange 道具添加到类型道具。现在它给了我错误。找不到名称“focusedInput”。找不到名称“onFocusChange”
有人可以帮我解决这个问题。谢谢。
解决方案
...
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>
);
}
推荐阅读
- java - Curator Framework 绕过 Zookeeper ACL 设置
- android - 创建一个带有圆圈文本的自定义按钮
- python - 如何在 mqtt.client 循环中处理 unix.timestamp 解码继续消息
- javascript - 是否可以从 Leaflet 中 getBounds() 的 fitBounds() 计算缩放级别?
- java - 转换列表
列表 在 Java 8 中 - java - 在最终发送之前进行 REST 调用的最佳方法是什么?
- google-cloud-dataflow - 奇怪的 Google Dataflow 作业日志条目
- linux - 通过 docker swarm 使用多个特定的网络接口
- .net - IBM MQ 客户端在 10 分钟后断开连接:IBM.XMS.IllegalStateException
- amazon-web-services - AWS Lambda 安排延迟执行运行一次