How to pass a function via onChange to a nested Material UI component #5178
-
Hello, I am have a Material UI nested component that look as follow:
While in my app.js,
And I am expecting to see 'Hello' with every keystroke in my console but, that is not the case. Does anyone know why? |
Beta Was this translation helpful? Give feedback.
Answered by
thanh-nguyen-95
May 13, 2021
Replies: 2 comments 4 replies
-
Your function TxtInput({ onChange: yourOnChange /* other props here */ }) {
return (
/* rest of the code */
<Controller
render={({ field: { onChange: rhfOnChange } }) => (
<TextField
required={required}
fullWidth
label={label}
id={name}
inputProps={{ 'aria-label': label }}
onBlur={onBlur}
onChange={(ev) => {
const { target: { value }} = ev
rhfOnChange(value)
yourOnChange(value)
}}
checked={value}
inputRef={ref}
{...rest}
/>
)}
/>
)
} |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
bluebill1049
-
Still new at this.
…On Wednesday, May 12, 2021, Thanh Nguyen ***@***.***> wrote:
Your TextInput does not receive onChange props. If you want to pass in a
custom onChange, try this:
function TxtInput({ onChange: yourOnChange /* other props here */ }) {
return (
/* rest of the code */
<Controller
render={({ field: { onChange: rhfOnChange } }) => (
<TextField
required={required}
fullWidth
label={label}
id={name}
inputProps={{ 'aria-label': label }}
onBlur={onBlur}
onChange={(ev) => {
const { target: { value }} = ev
rhfOnChange(value)
yourOnChange(value)
}}
checked={value}
inputRef={ref}
{...rest}
/>
)}
/>
)}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#5178 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARXQ5YRULR2T65FGEUPAMOTTNNVYHANCNFSM44ZKANWQ>
.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your
TextInput
does not receiveonChange
props. If you want to pass in a customonChange
, try this: