Custom wrapper component using "asField" causes warning for Checkbox and Select
See original GitHub issueV 3.24.0
We use a wrapper component so we can easily update all forms on our site. While upgrading, I noticed the use of Checkbox and Select components causes a warning, “Check to make sure you have not registered two fields with the fieldName.” Here is a simplified version of what we have:
import {Form, asField, BasicText, Select, Checkbox} from 'informed';
export const MyInputWrapper = asField(props => {
return <React.Fragment>
{{
'text': <BasicText {...props}/>,
'select': <Select {...props}/>,
'checkbox': <Checkbox {...props}/>
}[props.type]}
</React.Fragment>
});
function App() {
return (
<Form>
{({}) => (
<React.Fragment>
<MyInputWrapper type="text" field="myText"/>
<MyInputWrapper type="select" field="mySelect"/>
<MyInputWrapper type="text" field="myText"/>
</React.Fragment>
)}
</Form>
);
}
export default App;
Is there something obvious I am doing wrong here? The form appears to work fine, but the warnings are filling up console.
Issue Analytics
- State:
- Created 3 years ago
- Comments:27 (22 by maintainers)
Top Results From Across the Web
React a component is changing an uncontrolled input of type ...
If your state is initialized with props.value being null React will consider your Checkbox component to be uncontrolled.
Read more >Building a custom checkbox in React - LogRocket Blog
In this guide, we will cover how to build a custom checkbox in React without sacrificing accessibility for assistive technology.
Read more >Building a Checkbox Component with React and styled ...
We now have a simple React component that wraps the native checkbox element. This component will be the foundation of our styled checkbox....
Read more >Checkbox | Primer React
This Checkbox component is intended only as an ingredient for other custom components, or as a drop-in replacement for native HTML checkboxes ......
Read more >Changelog - ACF
Fix - Uploading multiple files nested in a subfield no longer causes a ... Fix - Fixed bug in Checkbox field missing "selected"...
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
Happens to the best of us haha
I definitely need to spend some time refactoring. I have a lot of “just make it work” code hanging about in here.