uiwjs / react-json-view

A React component for displaying and editing javascript arrays and JSON objects.
https://uiwjs.github.io/react-json-view/
MIT License
188 stars 11 forks source link

Support for React < 18 #53

Open JonathanAriass opened 2 months ago

JonathanAriass commented 2 months ago

Can we expect support for React < 18 in the future? I see that useId hook is being used and it is only available in React 18.

jaywcjlove commented 2 months ago

@JonathanAriass If we can support <18 without useId, I think we can accomplish this task.

EliazTray commented 1 week ago

@jaywcjlove Can we use 'useId' for React 18 and only support client-side for React < 18? refer https://github.com/react-component/util/blob/7aaa1d88174b30d7fb9c94b41b7a34cea5fc37f3/src/hooks/useId.ts#L43)

jaywcjlove commented 1 week ago

@EliazTray If this is the only issue, I can handle it easily.

import { useRef } from 'react';

function useIdCompat() {
  const idRef = useRef(null);
  if (idRef.current === null) {
    idRef.current = 'custom-id-' + Math.random().toString(36).substr(2, 9);
  }
  return idRef.current;
}

export default useIdCompat;
jaywcjlove commented 1 week ago

@JonathanAriass @EliazTray Upgrade v2.0.0-alpha.27

EliazTray commented 1 week ago

@JonathanAriass @EliazTray Upgrade v2.0.0-alpha.27

It took effect on React@16.13.1 ! Thanks for your quickly reply.