I am working with pern stack and when I try using useEffect or useState, I am getting this error. so, I used postgres to create database and used express to connect using pool
created a endpoint and tried fetching that in my code
import React, {useEffect , useState} from 'react';
import Table from './Table';
import Nav from './Navi';
import TemplateList from './TemplateList';
import {Tab,Tabs} from 'react-bootstrap';
class Dashboard extends React.Component{
const [tdata,setTdata] = React.useState([]);
info = async () => {
try {
const response = await fetch("http://localhost:8080/dashboard");
const dataServer = await response.json();
React.setTdata(dataServer);
} catch (err) {
console.error(err.message);
}
}
console.log(tdata);
React.useEffect(() => {
info();
}, []);
error
Failed to compile
./src/components/Dashboard.js
Line 7:9: Parsing error: Unexpected token
5 | import {Tab,Tabs} from 'react-bootstrap';
6 | class Dashboard extends React.Component{
> 7 | const [tdata,setTdata] = React.useState([]);
| ^
8 |
9 | info = async () => {
10 | try {