question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning with React Hooks order

See original GitHub issue

Prerequisites

What theme are you using?

material-ui

Version

4.2.2

Current Behavior

Running a pared down version of the schema-dependencies example from the playground in my own instance with material-ui v5 I’m getting the following react error when I click Add Item.

Warning: React has detected a change in the order of Hooks called by DefaultNormalArrayFieldTemplate. 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                  useContext
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

DefaultNormalArrayFieldTemplate@http://localhost:3001/static/js/bundle.js:34177:27
ArrayFieldTemplate@http://localhost:3001/static/js/bundle.js:34045:16
ArrayField@http://localhost:3001/static/js/bundle.js:30029:24
div
./node_modules/@emotion/react/dist/emotion-element-cbed451f.browser.esm.js/withEmotionCache/<@http://localhost:3001/static/js/bundle.js:660:66
FormControl@http://localhost:3001/static/js/bundle.js:8974:82
WrapIfAdditional@http://localhost:3001/static/js/bundle.js:34290:18
FieldTemplate@http://localhost:3001/static/js/bundle.js:34360:12
SchemaField@http://localhost:3001/static/js/bundle.js:31786:29
div
./node_modules/@emotion/react/dist/emotion-element-cbed451f.browser.esm.js/withEmotionCache/<@http://localhost:3001/static/js/bundle.js:660:66
Grid@http://localhost:3001/static/js/bundle.js:10809:87
div
./node_modules/@emotion/react/dist/emotion-element-cbed451f.browser.esm.js/withEmotionCache/<@http://localhost:3001/static/js/bundle.js:660:66
Grid@http://localhost:3001/static/js/bundle.js:10809:87
ObjectFieldTemplate@http://localhost:3001/static/js/bundle.js:34423:26
ObjectField@http://localhost:3001/static/js/bundle.js:31154:29
div
./node_modules/@emotion/react/dist/emotion-element-cbed451f.browser.esm.js/withEmotionCache/<@http://localhost:3001/static/js/bundle.js:660:66
FormControl@http://localhost:3001/static/js/bundle.js:8974:82
WrapIfAdditional@http://localhost:3001/static/js/bundle.js:34290:18
FieldTemplate@http://localhost:3001/static/js/bundle.js:34360:12
SchemaField@http://localhost:3001/static/js/bundle.js:31786:29
form
Mui5TagName@http://localhost:3001/static/js/bundle.js:35249:18
Form@http://localhost:3001/static/js/bundle.js:33129:24
./node_modules/@rjsf/core/dist/core.esm.js/withTheme/<@http://localhost:3001/static/js/bundle.js:33655:18 react-dom.development.js:86

And here is the minimal example index.js:

import './index.css';
import React from 'react';
import ReactDOM from 'react-dom';

import Form from '@rjsf/material-ui/v5';

const schema = {
  "title": "Schema dependencies",
  "description": "These samples are best viewed without live validation.",
  "type": "object",
  "properties": {
    "arrayOfConditionals": {
      "title": "Array of conditionals",
      "type": "array",
      "items": {
        "$ref": "#/definitions/person"
      }
    },
  },
  "definitions": {
    "person": {
      "title": "Person",
      "type": "object",
      "properties": {
        "Do you have any pets?": {
          "type": "string",
          "enum": [
            "No",
            "Yes: One",
            "Yes: More than one"
          ],
          "default": "No"
        }
      },
      "required": [
        "Do you have any pets?"
      ],
    }
  }
};

ReactDOM.render(<Form schema={schema} />,
        document.getElementById("root"));

Expected Behavior

I wouldn’t expect to get the React error that I got.

Steps To Reproduce

  1. I used create-react-app to create an app.
  2. Install the dependencies and packages required for rjsf and rjsf material-ui
  3. Copy the above code to src/index.js
  4. Have the public/index.html contain a <div id="root"></div>

Environment

- OS: Red Hat Enterprise Linux release 8.5 (Ootpa)
- Node: v18.6.0
- npm: 8.13.2

Anything else?

I think it may work with other themes, might be a material UI v5 issue. But I’m on an isolated network and don’t have access to other themes that work. I can’t get it to replicate on the shared playground version though, so I’m not sure what to make of that.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
heath-freenomecommented, Jul 21, 2022

In the upcoming rjsf v5 release, this issue will be moot as the hooks used to make the v4 and v5 releases co-exist will be gone. Instead, the @rjsf/material-ui release will be only used for v4 and a new @rjsj/mui release will be provided for v5. Look for an alpha (or beta) release in early august. NOTE, this release will have breaking changes

1reaction
cerpinscommented, Jul 21, 2022

Looks like the same issue. Not aware of other theme, file I reported issues on is part of MUI5 wrapper for RJSF, so it is related specifically to PR for MUI5 support.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"React has detected a change in the order of Hooks" but ...
I ran into this same error message in a component I was writing due to use of short-circuiting logic. This resulted in an...
Read more >
Rules of Hooks - React
By following this rule, you ensure that Hooks are called in the same order each time a component renders. That's what allows React...
Read more >
How to overcome warning 'React has detected a change in ...
How to overcome warning 'React has detected a change in the order of Hooks'? ; from "react"; import { useDispatch, useSelector } ;...
Read more >
Top 5 Mistakes in React Hooks - Monsterlessons Academy
This is why we are getting warning from React. React Hook "useState" is ... React Hooks must be called in the exact same...
Read more >
The post-Hooks guide to React call order - LogRocket Blog
Writing Hooks requires a shift in mindset from writing traditional class-based components. Start by learning the React call order ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found