[英]Why am I getting an unexpected token when using logical AND in an if statement?
[英]Why am I getting an unexpected token error in React when using createRef()
錯誤指向 class 中=
之前的空間。
這是錯誤C:\Users\crism\dream-in-green\src\components\myLineGraph.js:5:13: C:/Users/crism/dream-in-green/src/components/myLineGraph.js: Unexpected token (5:13)
它還說第一行代碼中的chartRef
從未被使用過,即使它在 class 下方的行中被調用。
有任何想法嗎?
import React, { Component, chartRef } from 'react';
import Chart from "chart.js";
export default class LineGraph extends Component {
chartRef = React.createRef();
}
我認為 chartRef 應該聲明為 const 而不是從反應庫中導入它
這是正確的方法: this.chartRef = React.createRef();
您不需要在文件頂部聲明它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.