jeudi 12 juillet 2018

"===" is an unexpected token in react

Greetings fellow denizens of StackOverflow. I am trying to write a react component which allows users to select a number (rating) from a drop down menu, which is then display and tracked persistently. However, I have a small problem. The computer doesn't like the "===" in my if statement. It says its an "unexpected token." What's the deal? Here's the if statement and everything that comes before it since I assume you don't need the rest.

import React, { Component } from "react";

 const loggedRatingVar = localStorage.getItem("rating0");

class DropDown0 extends Component {

 if (loggedRatingVar === null)
 {
  this.setState({displayRating: "?"});
 }
 else
 {
  this.setState({displayRating: loggedRatingVar});
 }

Aucun commentaire:

Enregistrer un commentaire