Use react-is for widget type check
See original GitHub issuePrerequisites
- I have read the documentation;
Description
Starting from React 16.3.0 the component is not always a function, but could be an object if it was wrapped with React.forwardRef
.
According to the guidelines, react-is
should be used for type validation.
The proper way of doing that is simply call - ReactIs.isValidElementType(Widget);
The possible place to fix: utils.js#L96
Steps to Reproduce
- Define
DescriptionField
and wrap it withReact.forwardRef
const DescriptionField = React.forwardRef((props, ref) => (
<YourComponent {...props} ref={ref} />)
)
- Define custom fields
const fields = { DescriptionField }
- Pass fields to SchemaForm
<SchemaForm
...
fields={fields}
...
/>
- Observe in the console
Uncaught Error: Unsupported widget definition: object
Expected behavior
Validation successfully passed.
Actual behavior
Validation is not passed, error is thrown.
Version
"react-jsonschema-form": "^1.0.3"
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Reactis User's Guide - Reactive Systems
Reactis User's Guide: model-based testing and validation of Simulink/Stateflow models of software.
Read more >How to use the react-is.isMemo function in react-is - Snyk
type === 'function' || reactIs.isMemo(element.type))) { { throw ReactError(Error("ReactShallowRenderer render(): Shallow rendering works only with custom ...
Read more >Accessibility - React
MDN Web Docs takes a look at this and describes how we can build keyboard-navigable JavaScript widgets. To set focus in React, we...
Read more >Testing React Apps - Jest
At Facebook, we use Jest to test React applications. ... Reminders that with Class components, we expect Jest to be used to test...
Read more >Software QA Testing and Test Tool Resources - ApTest
The tests in Haven are JUnit based so you can continue to use your JUnit enabled IDE when you write, debug and run...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same issue here for a custom widget wrapped in a (react-redux connect) HOC.
I’m trying to use custom widgets with rjsf and I have a HOC that wraps my components with
React.forwardRef
. I seem to be getting the same error in the most recent version of rjsf.I have updated the fiddle above to use the newest version of rjsf with this fix included. It still produces the same error..
As far as I can tell,
ReactIs.isForwardRef
will check for elements ofForwardRef
s, it doesn’t check for a component, which is the direct result ofReact.forwardRef
.