AnyRoad / react-json-view-lite

Lightweight Json view component for React
MIT License
161 stars 17 forks source link

`React.useId` doesn't exist in React 16/17 #20

Open s100 opened 12 months ago

s100 commented 12 months ago

PR #16 introduced a dependency on React's useId Hook. Unfortunately this Hook only exists in React 18, not React 16 or 17. react-json-view-lite is still meant to work in React 16, 17 and 18 which means unfortunately this was a breaking change. We still use React 17 (the React 18 upgrade is going to be difficult for us for reasons too complex to explain here) so this change broke us.

For now we are working around this by pinning to react-json-view-lite@1.1.0.

My suggestion would be to temporarily eliminate usage of React.useId and use some other unique ID generator instead, and release this as say react-json-view-lite@1.2.1. Later, if you want to move to use React.useId again, you can formally drop support for React 16 and 17 at the same time, document the breaking change, and bump your major version number to react-json-view-lite@2.

AnyRoad commented 12 months ago

Hi! I haven't noticed that the useId Hook exists only in the React 18 😢 Yes, I think the best solution is to eliminate the useId. I don't want to add any dependencies to the library since it was the original goal - to have no dependencies except React itself. But it might be challenging to write correct useId for all use cases (including SSR) from scratch.

I will release 1.2.1 asap.

AnyRoad commented 11 months ago

Just released version 1.2.1 without the useId dependency.