首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >[TypeError: null不是对象(计算'_this.state.confirm.confirm')]

[TypeError: null不是对象(计算'_this.state.confirm.confirm')]
EN

Stack Overflow用户
提问于 2020-12-01 16:36:33
回答 1查看 115关注 0票数 0

我正在尝试通过电话注册,但是我得到了一个错误:TypeError不是一个对象(计算'_this.state.confirm.confirm')。这是什么原因呢?

代码语言:javascript
复制
import auth from '@react-native-firebase/auth';

class PhoneVerificationPart extends Component {
    constructor(props) {
        super(props);
        this.state = {
            confirm: null,
            code: null
        };
    } 
signInWithPhoneNumber = async (+90....) => {

        const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
        this.setState({
            confirm: confirmation
        })
    }
    confirmCode = async () => {
        try {
            await this.state.confirm.confirm(this.state.code)
            await this.props.closeAndCreateCustomer()
        } catch (error) {
            console.log(error)
        }
    } }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-01 16:38:12

this.state.confirm最初被定义为null时,在它被重置之前,您将从该状态访问它。

使用这种方式

代码语言:javascript
复制
var phoneNumber = "+16505554567"; // should be in string

firebase.auth().signInWithPhoneNumber(phoneNumber)
    .then(function (confirmationResult) {
      // confirmationResult can resolve with the fictional testVerificationCode above.
      return confirmationResult.confirm(testVerificationCode)
    }).catch(function (error) {
      // Error; SMS not sent
      // ...
    });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65087110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档