2

Trying to compile my code & I can't get past this error; I've looked around on here at a few other questions but they're all pointing me in the direction of not extending the React.Component but I'm doing that?

The error I've got is:

bundle.js:72109 Uncaught TypeError: Cannot call a class as a function
    at _classCallCheck (bundle.js:72109)
    at TopBar (TopBar.js:14)
    at Game.render (Game.js:53)

TopBar.js:

import React from 'react';
import Engine from '../game-logic/GameEngineStore';
import GameSettingsStore from '../stores/GameSettingsStore';
import * as Clib from '../game-logic/clib';

function getState() {
  return {
    balanceBitsFormatted: Clib.formatSatoshis(Engine.balanceSatoshis)
  };
}

export default class TopBar extends React.Component {

  constructor(props, context) {
    super(props, context);
    this.state = getState();
  }

}

Game.js

import TopBar from './TopBar';

export default class Game extends React.Component {

  render() {
    const state = this.state;
    return (
      <div id="game-inner-container">
        { TopBar({ isMobileOrSmall: state.isMobileOrSmall }) }
      </div>
    );
  }

}

1 Answer 1

2

The error message seem to be clear - you are trying to call a class as a function. Just turn it into a JSX module:

<TopBar isMobileOrSmall={state.isMobileOrSmall} />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.