nkbt / react-collapse

Component-wrapper for collapse animation with react-motion for elements with variable (and dynamic) height
MIT License
1.12k stars 113 forks source link

Closing animation doesn't work on React <16.3 #253

Closed catriuspham closed 4 years ago

catriuspham commented 4 years ago

The block under doesn't work on older React which makes closing happens instantly without animation.

getSnapshotBeforeUpdate() {
  if (!this.container || !this.content) {
    return null;
  }
  if (this.container.style.height === 'auto') {
    const {clientHeight: contentHeight} = this.content;
    this.container.style.height = `${contentHeight}px`;
  }
  return null;
}

My suggestion is to use https://github.com/reactjs/react-lifecycles-compat.

nkbt commented 4 years ago

Peer dependency declares ^16.3.0 version, anything prior to that is not expected to work as intended