useRef
Create a persistent object between renders to capture from a node from VirtualDOM

Syntax

1
const ref = useRef(optionalCurrent);
Copied!

Example

1
import { useRef, useEffect, useState } from "atomico";
2
3
function component() {
4
const ref = useRef();
5
const [message, setMessage] = useState();
6
useEffect(() => {
7
const { current } = ref;
8
current.addEventListener("input", () => {
9
if (current.validity.typeMismatch) {
10
setMessage("Invalid!");
11
}
12
current.setCustomValidity("");
13
});
14
}, []);
15
return (
16
<host>
17
<input type="email" ref={ref} />
18
{message && <h1>{message}</h1>}
19
</host>
20
);
21
}
Copied!

Observation

The reference object is useful for referencing nodes between customHooks.
Last modified 3mo ago
Copy link
Edit on GitHub