bdwain
bdwain

Reputation: 1745

How to use react 16 features without dropping support for react 15

I'd like to use some of the new features of react 16 in a library I am working on. However, if I were to use componentDidCatch or ReactDOM.createPortal in a component I expose, a library running react 15 would presumably not support those methods right?

Is there a way to use the new features of React 16 without dropping support for React 15?

Upvotes: 0

Views: 86

Answers (1)

TLadd
TLadd

Reputation: 6884

In order to continue supporting React 15, you would need to check that whatever 16-only api exists before calling it. If it doesn't exist, then fallback to something else. Or maybe do nothing if it's more of an enhancement rather than core functionality of the library. So basically, maintain two different versions of the same functionality. Eventually, you drop support for 15 and delete the code path.

The 15 to 16 upgrade is fairly simple, so I personally wouldn't bend over backwards to continue supporting 15 for very long, but depends on the particular library and who uses it.

Upvotes: 1

Related Questions