TypeError:未定义不是一个对象('_this.props')
2019-07-31
289
我无法解决这个问题。你能帮助我吗? 评估“this.props.speciesSelection.modalize”
<BarcodeInput
speciesSelection={this.props.speciesSelection}
species={species[0]}
barcode={{ manufacturerValue: "", codeValue: "" }}
onChangeText={this.onChangeText}
/>
class BarcodeInput extends React.Component<Props, State> {
onPrefixPress = () => {
Keyboard.dismiss();
this.props.speciesSelection.modalize.open();
this.props.speciesSelection.modalizeOpened = true;
}
当我触摸按钮 onPrefixPress 时出现红框
1个回答
看起来您正在尝试调用一个未定义的函数(通过 props 传递)。
将
speciesSelection
prop 设为可选。
interface Props {
species: Species;
barcode: BarcodeState;
speciesSelection?: any;
onChangeText: (prop: keyof BarcodeState, value: string) => void;
}
interface State { }
class BarcodeInput extends React.Component<Props, State> {
onPrefixPress = () => {
Keyboard.dismiss();
this.props.speciesSelection && this.props.speciesSelection.modalize.open();
this.props.speciesSelection && this.props.speciesSelection.modalizeOpened = true;
}
或检查它未定义的原因。
Sanyam Jain
2019-07-31