Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"React has detected a change in the order of Hooks called by JsonNode" #46

Open
tordans opened this issue Jun 16, 2024 · 3 comments
Open

Comments

@tordans
Copy link

tordans commented Jun 16, 2024

I am getting react warnings in my dev console in some case where I use JsonView. Anyone know how to prevent this?

Warning: React has detected a change in the order of Hooks called by JsonNode. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks

   Previous render            Next render
   ------------------------------------------------------
1. useContext                 useContext
2. undefined                  useState
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    at JsonNode (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:573:21)
    at div
    at NameValue (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:212:22)
    at div
    at ObjectNode (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:365:23)
    at JsonNode (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:573:21)
    at div
    at NameValue (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:212:22)
    at div
    at ObjectNode (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:365:23)
    at JsonNode (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:573:21)
    at div
    at NameValue (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:212:22)
    at div
    at ObjectNode (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:365:23)
    at JsonNode (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:573:21)
    at div
    at NameValue (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:212:22)
    at div
    at ObjectNode (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:365:23)
    at JsonNode (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:573:21)
    at code
    at JsonView (webpack-internal:///(app-pages-browser)/./node_modules/react18-json-view/dist/es/index.mjs:711:26)
    at details
    at section
    at MapDebugHelper (webpack-internal:///(app-pages-browser)/./app/(map)/changesets/[id]/_components/Map/MapDebugHelper/MapDebugHelper.tsx:21:86)
@YYsuni
Copy link
Owner

YYsuni commented Jul 1, 2024

Can you provide a codesandbox for a review.

@tuan3w
Copy link

tuan3w commented Aug 12, 2024

Hi @YYsuni
Not sure if it's related, but I had a issue related to hooks:

Rendered more hooks than during the previous render.

I think the reason is that you are using hooks inside a condition expression, which causes this error:

} else {
const type = typeof node
const [editing, setEditing] = useState(false)
const [deleting, setDeleting] = useState(false)
const valueRef = useRef<HTMLSpanElement>(null)

@Houdou
Copy link

Houdou commented Sep 12, 2024

Hi @YYsuni
I have encountered the same error when the value passed to JsonView changed from an object to a string.
The behaviour matches the code pointed out by @tuan3w. Array.isArray(node) || isObject(node) would be returning false in the new render.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants