I am new in react js and i am following the Udemy course but I am getting the error that "Expected an assignment or function call and instead saw an expression no-unused-expressions".Basically I am using a firebase database to develop this application in this app user put their name as a student.
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 function expects you to return jsx to render, so:
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>
);
}
also, fix your indents, it helps to keep your sanity in the long run
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.