Controller requires it's props for custom components
See original GitHub issueDescribe the bug
When using Controller
with a custom input component, causes the Controller
to require the value
and onChange
props to be required.
To Reproduce Steps to reproduce the behavior:
- Open codesandbox
- Observe the type errors
Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-controller-template-qrtco
Expected behavior I would expect the typings to be smart enough to know if I have already passed the values or to know that the properties are injected.
Additional context
Also appears to be an issue with <input name="test" />
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:20 (19 by maintainers)
Top Results From Across the Web
How To Customize React Components with Props
In this tutorial, you'll create custom components by passing props to your component. Props are arguments that you provide to a JSX element....
Read more >Controller | React Hook Form - Simple React forms validation
This is a render prop. A function that returns a React element and provides the ability to attach events and value into the...
Read more >Turn Anything Into A Form Field With React Hook Form ...
Here we see the two props required to make our field component work with the Controller: value - It should show the current...
Read more >React native custom component props not working
But in your AppTextInput component, you are only handling two props, icon and placeholder . To make the other TextInput props work, you...
Read more >Custom Controls · React Redux Form
The mapping standard props to custom controls can be specified by the type of <Control> component you are using: // custom radio button...
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
So Bill posted the link I shared with him using the example of
react-router
v6 and their reasoning behind switching to an element based api instead of component.I think we can offer a single prop
as
/render
/element
to handle the use-cases. Offering multiple props will just cause confusion.For that single prop, we should be able to support render props or an element.
We then don’t have to worry about passing props through (ie.
myUniqueProp
) or handling conversion of their prop names (ie.onBlurKey
).The main issue that I see with this currently is instantiating the component without the
value
andonChange
props. Unless we required the render prop pass through.(props) => <TextFields {...props} />
or we might be able to do some typescript magic with an interface as I alluded to earlier.But that’s the issue is the DX isn’t good the way it currently stands.