What's the error in the code . Line 51:8: Parsing error: Unexpected token, expected "{"

405 views Asked by At

I am learning reactjs and I am getting parsing error in last line export App3; Please go through the below code guys and let me know what's the error(What's the error in the code . Line 51:8: Parsing error: Unexpected token, expected "{")

import React, { Component } from "react";
import Student from "./Student";
import useCustomHook from "./Customhook";

export default class App extends Component {
  constructor(props) {
    super(props);

    console.log("App - Constructor Called");
    console.log(props.name);
    this.state = {
      roll: "101",
    };
  }
  static getDerivedStateFromProps(props, state) {
    console.log("app2");
    console.log(props, state);
    return null;
  }

  componentDidMount() {
    // you can get data from server and set the data to state
    // Ajax is also called in component did mount method
    console.log("app - Component did mount working properly");
  }

  render() {
    console.log("app rendered");
    return (
      <div>
        <Student name="Abhishek" />
        {/* <h1>Hello</h1> */}
      </div>
    );
  }
}

function App3() {
  const data = useCustomHook();

  return (
    <>
      <h1> Hello {data.currState}</h1>
      <button type="button" onClick={data.customHandleIncrement}>
        Increment
      </button>
    </>
  );
};

export  App3;
1

There are 1 answers

0
Pankaj Shukla On BEST ANSWER

You have to use the syntax where use export before function App3(). Like this:

export function App3() {

Alternatively you can use this syntax:

export { App3 };