console.log & debugger statements in React.Components - unexpected token

5.6k views Asked by At

What is the proper way to add console.log and debugger statements to my React.Components?

Just dropping them in produces Unexpected token errors:

export class ManageCoursePage extends React.Component {
  debugger;
  constructor(props, context) {
    super(props, context);

A little more helpful but still produces Unexpected 'debugger' statement:

export class ManageCoursePage extends React.Component {

  constructor(props, context) {
    super(props, context);
    debugger;

Or even browsers' console errors out Uncaught SyntaxError: Unexpected token ;:

class Woot {
    debugger;
}

What exactly is going on here?

1

There are 1 answers

0
Cory House On BEST ANSWER

Move your debugger statement inside the constructor or a function and it'll work fine.