首页 > 解决方案 > 状态的属性值没有保存在 const 变量中?

问题描述

我是 React 的新手,我制作了 2 个状态对象,每个对象都有一个属性,然后我尝试将属性的值保存在 const 变量中,我正确地获取了第一个状态的值,但由于未知原因,其他的值没有显示在控制台中日志 在此处输入图像描述

这是2个州的代码

    state = {
    count: 23,
  };
 stateTwo = {
    number: 22
  };

这些是在控制台日志中调用值的 2 个函数

changNumber() {
    console.log("this is nmbr frm state: " + this.stateTwo.number);
    const { count } = this.stateTwo;

    console.log("this is : " + count);
    return count === 0 ? "ZERO" : count;
  }

  formatCount() {
    console.log("this is nmbr frm state: " + this.state.count);
    const { count } = this.state;

    console.log("this is : " + count);
    return count === 0 ? "ZERO" : count;
  }

标签: reactjsjsx

解决方案


推荐阅读