我试图在ReactJS中切换组件的状态,但我得到一个错误说明:
超出最大更新深度.当组件在componentWillUpdate或componentDidUpdate中重复调用setState时,可能会发生这种情况.React限制嵌套更新的数量以防止无限循环.
我没有在代码中看到无限循环,任何人都可以帮忙吗?
ReactJS组件代码:
import React, { Component } from 'react';
import styled from 'styled-components';
class Item extends React.Component {
constructor(props) {
super(props);
this.toggle= this.toggle.bind(this);
this.state = {
details: false
}
}
toggle(){
const currentState = this.state.details;
this.setState({ details: !currentState });
}
render() {
return (
<tr className="Item">
<td>{this.props.config.server}</td>
<td>{this.props.config.verbose}</td>
<td>{this.props.config.type}</td>
<td className={this.state.details ? "visible" : "hidden"}>PLACEHOLDER MORE INFO</td>
{<td><span onClick={this.toggle()}>Details</span></td>}
</tr>
)}
}
export default Item;
Run Code Online (Sandbox Code Playgroud) 我是React Native的新手,真的无法弄清楚为什么我无法将状态从一个组件传递到另一个组件
export default class questions extends Component {
constructor(props){
super(props);
this.state={
name: "stupidCount",
val: 1}
}
render(){
const { navigate } = this.props.navigation;
const { name2 } = this.state;
return(
<View style={styles.box}>
<TouchableOpacity onPress={() => navigate('Question1', stupidCount={name2})} >
<Text style={styles.h1}> Question 1 </Text>
</TouchableOpacity>
Run Code Online (Sandbox Code Playgroud)
第二部分,'问题1'
export default class Question2 extends Component {
render(){
const { navigate } = this.props.navigation;
console.log(stupidCount.val);
return(
<View style={styles.box}>
<Text style={styles.h1}>Question 2 </Text>
<Text> state test {stupidCount.val}</Text>
Run Code Online (Sandbox Code Playgroud)
非常感谢提前
我无法弄清楚为什么我的SQL选择查询一直失败 - 我是SQL的新手所以它可能是一个愚蠢的错误,但我无法在文档中找到答案.非常感谢提前
// connect to db
$mysqli = new mysqli("127.0.0.1", "maok08ab", "", "Portfolio");
if ($mysqli->connect_errno)
{
echo "Failed to connect to MySQL";
}
$username=$_POST["username"];
$email=$_POST["email"];
$hash=$_POST["password"];
$query = "SELECT * FROM users WHERE username = '$username'";
$result= mysqli_query($mysqli, $query);
if ($result == FALSE)
{
apologize("something went wrong");
}
Run Code Online (Sandbox Code Playgroud)