-
Notifications
You must be signed in to change notification settings - Fork 141
修复非受控形式下,Collapse 未重新渲染就执行 onChange 回调的问题 #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| if (!('activeKey' in this.props)) { | ||
| this.setState({ activeKey }); | ||
| this.setState({ activeKey }, () => { | ||
| this.props.onChange(this.props.accordion ? activeKey[0] : activeKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why nope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果有问题,需要给出具体问题的描述和重现。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我有一个非React的组件:
class NoReactComponent {
constructor(container) {}
}然后在Collapse中使用(非受控形式):
class App extends React.Component {
collapseOnChange = (keys) => {
// 由于目前的 Collapse,在执行 onChange 的时候
// 未在 this.setState 的回调中,导致我无法在 onChange 的回调中拿到
// this.refs.noReactComponentContainer
// 当然,我可以为 NoReactComponent 通过包装,成为一个 ReactComponent
// 然后
// ```
// <Panel header="This is panel header 1" key="1">
// <NoReactComponentToReactComponent />
// </Panel>
// ```
// 或者
// <Panel header="This is panel header 1" key="1">
// <div ref={noReactComponentContainer => { this.noReactComponentInstance = new NoReactComponent(noReactComponentContainer); }}></div>
// </Panel>
//
// 但是我觉得哪怕从语义上来说也应该在 this.setState 后 执行 onChange 会合适一点
// 我想 我和 https://github.com/react-component/collapse/issues/78 并不同
// 你可以仔细看下我的 PR 的 if else,都会执行 onChange
if (keys.indexOf('1') !== -1) {
this.noReactComponentInstance = new NoReactComponent(this.refs.noReactComponentContainer);
} else {
delete this.noReactComponentInstance;
}
}
render() {
return (
<Collapse
onChange={this.collapseOnChange}
>
<Panel header="This is panel header 1" key="1">
<div ref="noReactComponentContainer"></div>
</Panel>
<Panel header="This is panel header 2" key="2">
<div></div>
</Panel>
</Collapse>
)
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
试试 <Collapse destroyInactivePane={false}>
No description provided.