Open Claim0013 opened 1 year ago
This works for me. Just adapt to suit axios...
const [loading, setLoading] = useState(true);
const [JSON, setJSON] = useState([]);
useEffect(() => {
fetch(url).then(async (x) => {
const data = await x.json()
setJSON(data)
setLoading(false);
});
}, []);
return loading ? <div /> : <ReactJson src={JSON} />;
Hey guys!
I found this issue but it didn't help at all -> https://github.com/mac-s-g/react-json-view/issues/181
I am passing a fetched json to the
src
property and apparently the viewer isn't waiting for the promise to resolve and throws the exception instantly.The promise resolves right after the error. If I directly pass a json object to
src
, it works. I use an async/await method and pass it down to the component as such:<ReactJson src={getSrc()} collapseStringsAfterLength={40} ... />
Any tips?