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.

Use react-is for widget type check

See original GitHub issue

Prerequisites

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

  1. Define DescriptionField and wrap it with React.forwardRef
const DescriptionField = React.forwardRef((props, ref) => (
    <YourComponent {...props} ref={ref} />)
)
  1. Define custom fields
const fields = { DescriptionField }
  1. Pass fields to SchemaForm
<SchemaForm
   ...
   fields={fields}
   ...
/>
  1. 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:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
snirpcommented, Apr 30, 2020

Same issue here for a custom widget wrapped in a (react-redux connect) HOC.

1reaction
lyleunderwoodcommented, Jan 29, 2020

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 of ForwardRefs, it doesn’t check for a component, which is the direct result of React.forwardRef.

Read more comments on GitHub >

github_iconTop 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 >

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