首页 > 解决方案 > Uncaught (in promise) TypeError: o is not a function at this.setState

问题描述

我在 this.setState 中遇到错误。我必须绑定功能吗?还是有语法问题?有人可以帮忙吗?

    componentDidMount() {
    let mobile = false;
    this.setState({
        displayZipSearchPage : true,
        geolocation: {
            latitude: null,
            longitude: null,
            shared: false,
            supported: false,
        },
    });
    if (isNotEmptyObject(window) && 'navigator' in window) {
        if ('geolocation' in window.navigator) {
            navigator.geolocation.getCurrentPosition(
                (pos) => {
                    this.setState({  'The error occurs here'
                        geolocation: {
                            latitude: pos.coords.latitude.toString(),
                            longitude: pos.coords.longitude.toString(),
                            shared: false,
                            supported: true,
                        },
                    });
                },
                console.error,
                this.geoOptions,
            );
        }
    }
}

标签: javascriptreactjstypescript

解决方案


推荐阅读