gpt4 book ai didi

javascript - 如何从回调函数访问状态

转载 作者:行者123 更新时间:2023-11-29 17:52:36 25 4
gpt4 key购买 nike

<分区>

我在 React Native 中有一个组件:

export default class Screen extends Component {
constructor(props){
super(props);
this.state = {
prop1: false,
prop2: simpleFunc
};
}
simpleFunc = () => { /*...*/ }

componentWillMount() {
BackgroundGeolocation.on('location', this.onLocation);

最后一行是将在新位置调用的回调方法。
从该方法我无法访问 this.statethis.simpleFunc()

我应该怎么做才能从回调函数更新状态?

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