gpt4 book ai didi

javascript - ReactJS - 未捕获的类型错误 : Cannot call a class as a function

转载 作者:行者123 更新时间:2023-12-04 10:53:33 24 4
gpt4 key购买 nike

试图编译我的代码,我无法克服这个错误;我在这里查看了其他一些问题,但它们都在向我指出不扩展 React.Component 的方向。但我正在这样做?

我得到的错误是:

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();
}

}

游戏.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>
);
}

}

最佳答案

错误消息似乎很清楚 - 您正在尝试将类作为函数调用。把它变成一个 JSX 模块:

<TopBar isMobileOrSmall={state.isMobileOrSmall} />

关于javascript - ReactJS - 未捕获的类型错误 : Cannot call a class as a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59343835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com