繁体   English   中英

运行npm start命令时React Redux项目的语法错误

[英]Syntax Error for React Redux Project when running npm start command

我正在GitHub上构建一个React-Redux Scoreboard项目,当我运行“ npm start”时,在我的终端中继续遇到错误。 该错误表明我的文件“ src / containers / player.js”和“ src / containers / Scoreboard.js”的语法不正确。 这是我的GitHub存储库的链接: GitHub存储库如果有人可以帮助我解决此错误,我将不胜感激!

Player.js

   import * as PlayerActionTypes from '../actiontypes/player';

const initialState = [
    {
      name: "Emmanuel",
      score: 31,
    },
    {
      name: "Arsenio",
      score: 35,
    },
      {
      name: "Melanie",
      score: 30,
    },
        {
      name: "Peter",
      score: 25,
    },
        {
      name: "Mani",
      score: 27,
    },
        {
      name: "Miguel",
      score: 29,
    },
        {
      name: "Jason",
      score: 22,
    },
        {
      name: "Missy",
      score: 28,
    },
];

export default function Player(state=initialState, action) {
  switch(action.type) {
    case PlayerActionTypes.ADD_PLAYER:
      return [
        ...state,
        {
          name: action.name,
          score: 0
        }
      ];

    case PlayerActionTypes.REMOVE_PLAYER:
      return [
        ...state.slice(0, action.index),
        ...state.slice(action.index + 1)
      ];

    case PlayerActionTypes.UPDATE_PLAYER_SCORE:
      return state.map((player, index) => {
        if(index === action.index) {
          return {
            ...player,
            score: player.score + action.score
          };
        }
        return player;
      });

    default:
      return state;
  }
}

Scoreboard.js:

import React, { Component, PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as PlayerActionCreators from '../actions/player';
import Player from '../components/Player';
import Header from '../components/Header';
import AddPlayerForm from '../components/AddPlayerForm';

class Scoreboard extends Component {

  static propTypes = {
    players: PropTypes.array.isRequired
  };

  render() {    
    const { dispatch, players } = this.props;
    const addPlayer = bindActionCreators(PlayerActionCreators.addPlayer, dispatch);
    const removePlayer = bindActionCreators(PlayerActionCreators.removePlayer, dispatch);
    const updatePlayerScore = bindActionCreators(PlayerActionCreators.updatePlayerScore, dispatch);

    const playerComponents = players.map((player, index) => (
      <Player 
        index={index}
        name={player.name}
        score={player.score}
        key={player.name}
        updatePlayerScore={updatePlayerScore}
        removePlayer={removePlayer}
      />
    ));

    return (
      <div className="scoreboard">
        <Header players={players} />
        <div className="players">
          { playerComponents }
        </div>
        <AddPlayerForm addPlayer={addPlayer} />
      </div>
    );
  }
}

const mapStateToProps = state => (
  {
    players: state
  }
);

export default connect(mapStateToProps)(Scoreboard);

终端错误

在我的Scoreboard.js文件中,我应该在第一行中键入“ PropTypes”,而不是引起错误的“ Protypes”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM