[英]getting an error of Expected an assignment or function call and instead saw an expression no-unused-expressions in react
[英]Getting the error that Expected an assignment or function call and instead saw an expression no-unused-expressions?
我是 react js 的新手,我正在學習 Udemy 課程,但我收到了“期望賦值或函數調用,卻看到一個表達式 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;
render 函數希望您返回 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>
);
}
此外,修復您的縮進,從長遠來看有助於保持您的理智
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.