Skip to content

Problem with import react-json-view #1791

Closed Answered by hollandThomas
igorwessel asked this question in Q&A
Discussion options

You must be logged in to vote

A couple of things

react-json-view references document 7 times. Doing so leads to errors when using SSR with React, like Remix does. SSR means that the JavaScript code is not (only) executed in a browser but also in non-browser environments like Node.js or others. There is no document in non-browser environments.
You can test this by adding a console.log(document); to any component, which won't work. We can use browser-only APIs by wrapping them in an useEffect as described by the docs.

export default function Index() {
    console.log(document); // won't work

  useEffect(() => {
    console.log(document); // works
  }, []);

  return <div>Hello</div>;
}

This doesn't help with your use c…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sergiodxa
Comment options

Answer selected by igorwessel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants