-
Using just React, we can utilize const DataAttr = () => {
const userNameRef = useRef(null);
return (
<div>
<input name="username" type="text" data-userid="111" ref={userNameRef} />
<button onClick={e => {if(userNameRef.current) userNameRef.current.dataset.userid = "555"}}>Set</button>
<button onClick={e => {alert(userNameRef.current && userNameRef.current.dataset.userid)}}>Get</button>
</div>
);
} How can this be achieved using |
Beta Was this translation helpful? Give feedback.
Answered by
jorisre
Apr 8, 2021
Replies: 1 comment 5 replies
-
Hi @atshakil I'm not sure to understand what you want to do. Do You want to put |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
atshakil
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @atshakil
I'm not sure to understand what you want to do. Do You want to put
data-*
in React Hook Form ?If
data-*
is like defaultValues then you can use directly defaultValues:useForm({ defaultValues: { ... } })