Reactjs 为什么此React状态返回为未定义?

Reactjs 为什么此React状态返回为未定义?,reactjs,Reactjs,我的React组件中出现以下错误: Failed to compile. ./src/components/GameInfo.js Line 13: 'isPlaying' is not defined no-undef Search for the keywords to learn more about each error. 但我在同一个文件中定义了该状态,整个情况如下: import React from 'react'; import { Layer, Stage } fro

我的React组件中出现以下错误:

Failed to compile.

./src/components/GameInfo.js
Line 13:  'isPlaying' is not defined  no-undef

Search for the keywords to learn more about each error.
但我在同一个文件中定义了该状态,整个情况如下:

import React from 'react';
import { Layer, Stage } from 'react-konva';
import { connect } from 'react-redux';
import Banner from './Banner.js';
import CurrentTetromino from '../containers/CurrentTetromino.js';
import ActiveTetrominos from '../containers/ActiveTetrominos.js';
import gameConstants from '../gameConstants.js';
import style from '../styles/styles.css';

const { fieldHeight, fieldWidth } = gameConstants;

let GameField = ({ isPlaying, isPaused, isGameOver }) => {
if (isPlaying) {
    return (
        <div style={{display: 'inline'}}>
            <div className={style.gameField}>
                <Stage width={fieldWidth} height={fieldHeight}>
                    <Layer>
                        <CurrentTetromino />
                        <ActiveTetrominos />
                    </Layer>
                </Stage>
                { isPaused ? <Banner label="PAUSED" color="black" opacity=".5" /> : null}
            </div>
            { isGameOver ? <Banner label="GAME OVER" color="red" opacity=".8" /> : null}
        </div>
    );
}
return null;
};

const mapStateToProps = ({ gameStatus }) => ({
isPlaying: gameStatus !== 'IDLE',
isPaused: gameStatus === 'PAUSED',
isGameOver: gameStatus === 'GAME_OVER',
});

GameField = connect(mapStateToProps)(GameField);

export default GameField;
我想导致这种情况的错误也会在isPaused和isGameOver中类似地返回

我不知道为什么它没有在mapStateToProps中拾取这些常量。不幸的是,对于React,它实际上只告诉我第13行发生错误的那一行


任何建议都将不胜感激。

这个愚蠢的网站不会让我发表评论,但我会检查你的mSTP中的游戏状态是否正常。我不会执行隐式返回,而是将其更改为显式,并在mSTP中记录gameStatus。或者在那里安装一个调试器。这是我检查的第一本能

const mapStateToProps = ({ gameStatus }) => {
   console.log(gameStatus);
   return { 
      isPlaying: gameStatus !== 'IDLE',
      ....
   }
}

如果你能分享这件事,我可能会帮你更多。否则祝你好运,希望这有助于解决这个问题。

在经典的编程方式中,我的拼写错误是“isplay”而不是“isplay”

谢谢你的帮助

isPlaying的定义是什么?从技术上讲,isPlaying是从道具中解构出来的。即使props.isplay不存在,它仍然应该将值设置为未定义,如果isplay。。。而不是抛出错误。就像@wdm状态一样,即使gameStatus未定义,它也应该返回bool。我认为这是一个拼写错误和/或应用程序进程需要重新启动和/或如果你有一个服务人员,它需要从浏览器缓存中删除,因为它可能会弄乱你的编译器。照目前的情况,我无法复制您的问题。