0

I have a problem on codesandbox, that is not reproducable in normal setup.

The error is: "Invalid hook call. Hooks can only be called inside of the body of a function component." - invariant 321

  1. I only use function components
  2. There actually was a problem in a dependency (DraftJS)
  3. Downgraded react and react-dom to 16.12 - where the error was not existing
  4. Removed the DraftJS dependency mounting at all (removed the schema widget: 'Text')
  5. Removed some other call - to setState, not a hook - inside a setTimeout
  6. Checked the package-lock.json, react and react-dom are the same version

The error still exists in the sandbox, when installing offline no error comes up at all.

Error was primary triggered from src/Schema/DemoEditor.js

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Michael B.
  • 899
  • 10
  • 16
  • The error in your question is not the error thats presented in the codesandbox – GBWDev Mar 16 '20 at 09:25
  • your problem is your useState, calling functions inside your set state methods, and then additionally 'watching' the functions in the array of usestate, rather than the state values – GBWDev Mar 16 '20 at 09:34
  • when u fix the useEffect problem, the real error is: `given store must be a valid EditorStore in SchemaEditorProvider` so theres something wrong with that as well – GBWDev Mar 16 '20 at 09:40
  • Actually it seems that there is some issues with codesandbox example. I've tested it locally and on [repl](https://repl.it/@elbakerino/ui-schema-cra) and it works. – awran5 Mar 16 '20 at 10:30
  • @GBWDev calling functions within setState is what i do everywhere, why adding another unneeded variable beforehand? "watching" is needed, without those functions in dependencies, it is really error-prone (also my strict eslint rules would throw that normally, `react-hooks/exhaustive-deps`). "given store errror": because you didn't set the values in the state - like it was set in useEffect :) – Michael B. Mar 16 '20 at 10:59
  • @awran5 thanks, and i really don't know how to fix that, the original codesandbox is autogenerated from the github repository, repl and local works without any errors/warnings at all – Michael B. Mar 16 '20 at 11:00

0 Answers0