我正在开发一个使用react-swipeable的组件。当用户向左或向右滑动时,卡值会发生变化。
const values = [
'1',
'2',
'3',
'5',
'8',
'13',
'20',
'40'
]
export default class UserContainer extends React.PureComponent{
constructor() {
super();
this.state = {
currentIndex: 0,
cardValue:values[0]
}
this.swipedRight = this.swipedRight.bind(this);
}
swipedRight(){
var newIndex = this.state.currentIndex;
if(newIndex !== 0){
newIndex-=1;
this.setState({
currentIndex : newIndex,
cardValue: values[newIndex]
});
}
}
render(){
return(
<Grid>
<Row is="center">
<div style={{width:'170px'}} className={this.state.animationClass}>
<Swipeable onSwipedUp={this.swipedUp} onSwipedRight={this.swipedRight} onSwipedLeft={this.swipedLeft} >
<User cardValue={this.state.cardValue} userName={this.props.params.userName} />
</Swipeable>
</div>
</Row>
</Grid>
);
}
}当我运行npm-start (我使用的是create-react-app)时,它工作得很好。我使用heroku部署它,首先运行npm run build,然后推送到heroku master。
当我尝试在生产环境中使用我的应用程序时,路由是有效的,但当我滑动(使用chrome切换设备工具栏)时,它不会自动更新。如果我按F12,它就会更新。我想知道出了什么问题。
我的应用链接是:https://poc-planning-poker.herokuapp.com/
1)使用上面的链接打开两个选项卡2)在Tab#1上,单击新建文件室,然后复制roomId 3)在Tab#2上,填写昵称,在代码字段中粘贴roomId,然后单击加入文件室
Tab#1应该会随着刚刚加入的用户自动更新(它在开发环境中工作)。它只会在我按下F12时更新,这很奇怪。
有什么想法吗?
编辑:源代码在这里:https://github.com/danruziska/poc-planning-poker
Edit2:我还意识到,当我在数组中使用setState时,它会调用render,但UI不会自动更新。如果我setState一个值,它就能工作...
发布于 2017-02-22 23:12:41
我找到了(某种程度上)的问题。这与我使用的另一个组件react-inline-grid有冲突。当我使用Grid时,它又能工作了。
https://stackoverflow.com/questions/42378034
复制相似问题