我正在使用 react-card-flip - https://github.com/AaronCCWong/react-card-flip在点击时翻转照片。但是当我有多个时,如果我只点击一个,它就会全部翻转。看起来它甚至只需单击一下即可自动更新所有状态。有没有办法纠正这个问题?
import React, { Component } from "react"
import string from "prop-types"
import styles from "./styles.module.less"
import ReactCardFlip from "react-card-flip"
class VerticalFlip extends Component {
constructor() {
super()
this.state = {
isFlipped: false,
}
this.handleClick = this.handleClick.bind(this)
}
handleClick(event) {
event.preventDefault()
this.setState(prevState => ({ isFlipped: !prevState.isFlipped }))
}
render() {
return (
<div className={styles.cards}>
{team.map((s, i) => {
return (
<div key={i}>
<ReactCardFlip
isFlipped={this.state.isFlipped}
flipSpeedFrontToBack={1.0}
flipSpeedBackToFront={1.0}
flipDirection="vertical"
>
<div key="front" style={this.props.card} onClick={this.handleClick}>
<div className={styles.ImageContainer}>
<img style={this.props.image} src={s.src} alt={s.alt} />
</div>
</div>
<div key="back" style={this.props.card} onClick={this.handleClick}>
<div className={styles.TextContainer}>
<p>
<div className={styles.name}>{s.firstname}{s.lastname}</div>
<div className={styles.position}>{s.position}</div>
</p>
</div>
</div>
</ReactCardFlip>
</div>
);
})}
</div>
)
}
}
VerticalFlip.propTypes = {
firstName: string.isRequired,
lastName: string.isRequired,
role: string,
}
export default VerticalFlip