Allow Controller to specify custom onBlur/onChange handlers #3671
-
I am currently working with RHF and am integration an "auto save" feature that triggers on the To be clear, RHF already supports this using render props! This discussion is about whether it would be a nicer API to allow these to be specified on the Currently working: Using render props to compose a new custom const now = (
<Controller
name="myField"
control={control}
rules={{ required: true }}
render={({ onBlur, ...renderProps }) => (
<TextField
label="My Field Label"
helperText="Some value"
required
{...renderProps}
onBlur={e => {
e.persist();
onBlur(e);
myCustomOnBlurLogic(e);
}} />
)}
/>
); Proposal: Currently, this code would not trigger the const proposal = (
<Controller
name="myField"
control={control}
as={TextField}
rules={{ required: true }}
{/* use the merge for TextField props */}
required
label="My Field Label"
helperText="Some value"
{/* Proposal: Allow event handler extension */}
onBlur={myCustomOnBlurLogic}
/>
); The reason I like the proposed example is that it is more inline with how the current Anyway, no big deal to write it the first, working, way but would be curious to hear if the extension pattern is something that could be supported in the future :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
hey @jannisg that's actually the API with V5: https://react-hook-form.com/v5/api#Controller however it does issues, especially way too many props to be taking care of. In fact, in the next major version, we will most likely deprecate |
Beta Was this translation helpful? Give feedback.
-
Are there plans for this API coming back? @bluebill1049 For now, I'm overwriting the onBlur and updating a context store with the blurred field
Would there be any performance gain in using handleSubmit rather than accessing the value directly here? |
Beta Was this translation helpful? Give feedback.
hey @jannisg that's actually the API with V5: https://react-hook-form.com/v5/api#Controller however it does issues, especially way too many props to be taking care of. In fact, in the next major version, we will most likely deprecate
as
props. thanks for the suggestion and feedback tho 👍