从API检索数据并更新商店时,我的组件的道具未更新。 调用“ getGames”方法,但不能使用“ getGame”方法,它可以正常工作。
我知道该方法/减速器可以正常工作,因为该方法在其他组件中也可以正常工作。 另外,我知道该操作正在被调用(redux开发工具)。
组件:
class Dashboard extends Component {
static propTypes = {
games: PropTypes.array.isRequired,
game: PropTypes.object,
getGames: PropTypes.func.isRequired,
getGame: PropTypes.func.isRequired,
};
constructor(props) {
super(props);
this.openGamePanel = this.openGamePanel.bind(this);
this.state = {
rightPanelOpen: false,
gameid: null,
};
}
componentDidMount() {
this.props.getGames();
}
openGamePanel(game) {
this.props.getGame(game.id);
this.setState({
gameid: game.id,
});
}
check() {
console.log(this.props);
}
toggleRightPanel() {
this.setState({
rightPanelOpen: !this.state.rightPanelOpen,
});
}
render() {
return (
<Fragment>
<Map games={this.props.games} />
<UIPanelLeft
games={this.props.games}
check={() => this.check()}
handleOpenGamePanel={this.openGamePanel}
/>
{this.props.game ? (
<GamePanel game={this.props.game} key={this.props.game.id} />
) : (
<div></div>
)}
</Fragment>
);
}
}
const mapStateToProps = (state) => ({
games: state.games.games,
game: state.game,
location: state.location,
});
export default connect(mapStateToProps, { getGames, getGame })(Dashboard);
答案 0 :(得分:0)
已解决:
我从商店里拿了state.game,而不是state.games.game。
我生命中90分钟的片段。