gpt4 book ai didi

javascript - 类型错误 : undefined is not an object ('_this.props' )

转载 作者:行者123 更新时间:2023-11-30 19:22:42 24 4
gpt4 key购买 nike

我无法解决这个问题。你能帮助我吗。评估“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 时出现红色框

最佳答案

看起来您正在尝试调用一个未定义的函数(通过 props 传递)。使 speciesSelection 属性可选。

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;
}

或者检查它为什么未定义。

关于javascript - 类型错误 : undefined is not an object ('_this.props' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57289702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com