I am trying to use react-jsonschema-form. I created a new react project, and edited index.js using the “Usage” code in the react-jsonschema-form documentation. This is the code:
import React from 'react';
import ReactDOM from 'react-dom/client';
import {render} from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import Form from '@rjsf/core';
import { RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';
const schema: RJSFSchema = {
title: 'Todo',
type: 'object',
required: ['title'],
properties: {
title: { type: 'string', title: 'Title', default: 'A new task' },
done: { type: 'boolean', title: 'Done?', default: false },
},
};
const log = (type) => console.log.bind(console, type);
render(
<Form
schema={schema}
validator={validator}
/>,
document.getElementById('root')
);
When I run the code, I get this warning in the JS console:
index.js:23 Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
And then this error:
Cannot read properties of null (reading 'useCallback')
TypeError: Cannot read properties of null (reading 'useCallback')
at useCallback (http://localhost:3000/static/js/bundle.js:31433:25)
at SchemaFieldRender (http://localhost:3000/static/js/bundle.js:3059:88)
at renderWithHooks (http://localhost:3000/static/js/bundle.js:51769:22)
at mountIndeterminateComponent (http://localhost:3000/static/js/bundle.js:55740:17)
at beginWork (http://localhost:3000/static/js/bundle.js:57043:20)
at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:42025:18)
at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:42069:20)
at invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:42126:35)
at beginWork$1 (http://localhost:3000/static/js/bundle.js:62024:11)
at performUnitOfWork (http://localhost:3000/static/js/bundle.js:61272:16)
No idea why this happening, would appreciate any help.