【发布时间】:2019-04-08 18:57:03
【问题描述】:
我遇到了问题
"react-navigation": "2.18.2",
"@types/react-navigation": "2.13.0",
"typescript": "3.1.6",
我试图在子组件中使用withNavigation HOC,但这会导致父组件说并非所有必要的道具都被传递下来。即
在父母中:
render() {
return (
<Child
someProp={true}
/>
);
}
在孩子中:
export interface IChildProps {
someProp: boolean
}
class Child extends React.Component<IChildProps & NavigationInjectedProps> {
render() {
return (<Text>Child component </Text>)
}
}
export default withNavigation(Child)
我在父级中收到此错误:
Property 'navigation' is missing in type ...,表示父母似乎无法弄清楚navigation是出于某种原因通过withNavigation HOC传递给孩子的?
我当然可以从父级传递navigation 属性,但这会使withNavigation 有点无用,只是将问题移到祖先链上:笑脸:
我查看了类型定义,但找不到任何错误。有人可以帮我解决问题吗?
【问题讨论】:
标签: typescript react-native react-navigation higher-order-functions