react-json-view icon indicating copy to clipboard operation
react-json-view copied to clipboard

src cannot be undefined?

Open jonathan-meyer opened this issue 9 months ago • 1 comments

In the pervious versions of this component the src property could be set to undefined which is handy in my case as I use this as a debug tool for seeing the internals of my React page. Could we add the undefined type to src? Or am I missing something on how to use this component correctly?

import ReactJson from '@microlink/react-json-view';
import { useEffect, useState } from 'react';

const Foo = () => {
  const [value, setValue] = useState<string>();

  useEffect(() => {
    setTimeout(() => {
      setValue('hi');
    }, 1000); // Simulate a delay
  }, []);

  return <ReactJson src={value} />;
};

export default Foo;

Image

Thanks!

jonathan-meyer avatar Apr 17 '25 14:04 jonathan-meyer

try

import ReactJson from '@microlink/react-json-view';
import { useEffect, useState } from 'react';

const Foo = () => {
  const [value, setValue] = useState<string>();

  useEffect(() => {
    setTimeout(() => {
      setValue('hi');
    }, 1000); // Simulate a delay
  }, []);

  return <ReactJson src={value || {}} />;
};

export default Foo;

Dhyrkas avatar Jul 14 '25 18:07 Dhyrkas