gpt4 book ai didi

javascript - 收到预期赋值或函数调用却看到表达式 no-unused-expressions 的错误?

转载 作者:行者123 更新时间:2023-12-02 21:43:45 31 4
gpt4 key购买 nike

我是 React js 新手,正在学习 Udemy 类(class),但收到错误消息“预期分配或函数调用,而是看到表达式 no-unused-expressions”。基本上,我正在使用 firebase 数据库来在此应用程序中开发此应用程序,用户将自己的名字设为学生。

import React, { Component } from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';

var firebase=require('firebase');
var uuid=require('uuid');

var firebaseConfig = {
apiKey: "AIzaSyAwXf9-4PgY0ttsGy1FHmyLHZOFO1oVcic",
authDomain: "uservey-206d4.firebaseapp.com",
databaseURL: "https://uservey-206d4.firebaseio.com",
projectId: "uservey-206d4",
storageBucket: "uservey-206d4.appspot.com",
messagingSenderId: "723372497898",
appId: "1:723372497898:web:0ebb13dcb9ce6d2f6eb093",
measurementId: "G-J6190VVVQH"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);

class Survey extends Component {
constructor(props) {
super(props);
this.state = {
uid:uuid.v1(),
studentName:'',
answers:{
answer1:'',
answer2:'',
answer3:'',
},
isSubmitted:false
};
}
render() {
var studentName;
var questions;
if(this.state.studentName ==='' && this.state.isSubmitted === false){
<div>
<h1>Please Enter Your Name:</h1>
<input type="text" className="form-control" placeholder="Please Enter Your Name"/>
</div>
}
return(
<div>
{studentName}
------------------------------
{questions}
</div> );}
}

export default Survey;

最佳答案

渲染函数期望您返回 jsx 进行渲染,因此:

 render() {
if(this.state.studentName ==='' && this.state.isSubmitted === false){
return (
<div>
<h1>Please Enter Your Name:</h1>
<input type="text" className="form-control" placeholder="Please Enter Your Name"/>
</div>
)
}

return (
<div>
{studentName}
------------------------------
{questions}
</div>
);
}

另外,修复你的缩进,从长远来看它有助于保持你的理智

关于javascript - 收到预期赋值或函数调用却看到表达式 no-unused-expressions 的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60313712/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com