reactjs - 反应本机设置状态不起作用
问题描述
我正在尝试更新反应本机组件中的状态。但它得到错误,有人可以帮助我。
我正在使用 react-native-cli 版本:2.0.1 react-native 版本:0.55.4
这是我的代码:
import React, { Component } from 'react'
import {
Button,
Text,
View,
} from 'react-native';
export class ToggleButton extends Component {
state = {
isDone: false
};
onAction() {
const value = !this.state.isDone;
this.setState({ isDone: value });
const newValue = this.state.isDone;
console.log(newValue);
}
render() {
return (
<View>
<Button
title="Action"
onPress={this.onAction}
/>
</View>
)
}
}
export default ToggleButton;
解决方案
推荐阅读
- angular - Angular如何避免选中复选框?
- html - 在右下角没有“位置:绝对”
- python - Python for循环不迭代i = 1,2只输出第一次迭代
- python - 为什么我的 DataFrame 将添加内容复制到特定列?
- android - 即时运行不适用于运行 android 9.0 的 Google 像素 2xl
- javascript - 深度克隆对象不运行功能 - javascript
- r - 在没有错误的并行循环中附加 CSV
- python - Django-admin TypeError: __init__() 得到了一个意外的关键字参数“allow_abbrev”
- javascript - TypeError:更新后无法读取未定义的属性“任何”
- java - 从 CSV 文件读取时出现 NumberFormatException 错误