【发布时间】:2019-10-29 15:04:36
【问题描述】:
我的 React Native 应用程序中有以下类(使用 Typescript):
class Component1 extends React.Component<IntroProps, {}> {
constructor(props){
super(props)
console.log(props.onLayout)
}
...
}
我在View 类的文档中读到,任何View 或从它继承的组件都具有this.props.onLayout。但是,这会记录undefined,如果我使用this.props.onLayout 而不是props.onLayout,它会给出警告“属性'onLayout' 在'Readonly & Readonly' 类型上不存在”。
我见过其他人在他们的组件中使用this.props.onLayout 的例子与我的类似,除了我使用 TypeScript。
我想知道的:
为什么我无法在此处访问this.props.onLayout,如何访问?
【问题讨论】:
标签: javascript reactjs typescript react-native