我遇到了折叠问题。单击处理程序正在工作,但额外区域仅在下一次重写父组件后(未)折叠。这是两个方面的坏消息
- 点击时没有动画
- 当父组件没有更改其道具时,子组件将被重绘(您可以看到该
extra
值是此类私有的)。
经过搜索,我之前找不到这个问题。如何让折叠与按钮单击相关联。
import { Grid, Row, Col, Input, Button, Collapse } from 'react-bootstrap';
import styles from './styles';
export class Entry extends Component {
constructor(props) {
super(props);
this.extra = false; // alternative that also did not work
this.settings = {extra:false};
}
render() {
const { entryData } = this.props;
return (
<div className={styles}>
<h3 className="orgname">{entryData.orgName}</h3>
<Button bsSize="xsmall" onClick={this.close}>X</Button>
<Button onClick={ () => {this.settings.extra = !this.settings.extra; console.log("click", this.settings.extra) } } >
more...
</Button>
<Collapse in={this.settings.extra}>
<div>
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.
Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
</div>
</Collapse>
</div>
);
}
}