Replies: 1 comment
|
So this is more of a lint/ref-access pattern issue than a RHF issue. Two practical options:
For example: const [signatureFile, setSignatureFile] = useState<File | null>(null)
const captureSignature = useCallback(() => {
setSignatureFile(ref.current?.toFile() ?? null)
}, [])
<SignaturePad ref={ref} onEnd={captureSignature} />
const onSubmit = handleSubmit(async values => {
const file = sig ? signatureFile : null
const { blob } = file ? await upload(file) : { blob: null }
// ...
})If you keep the current approach, I’d still say the important point is: RHF is not invoking your submit callback during render. The rule is just being conservative about |
|
You're correct — What's happeningThe Fix optionsOption 1: Suppress the specific lint error (quickest) const onSubmit: SubmitHandler<ReceiptFormInput> = async (value) => {
let sigUrl: string;
if (sig) {
// eslint-disable-next-line react-compiler/react-compiler
const { blob } = await upload(ref.current?.toFile());
sigUrl = blob?.url || '';
}
// ...
};Option 2: Extract the ref read to a callback (cleanest) Move the ref access into a const getSignatureFile = useCallback(() => {
return ref.current?.toFile();
}, []);
const onSubmit: SubmitHandler<ReceiptFormInput> = async (value) => {
if (sig) {
const { blob } = await upload(getSignatureFile());
sigUrl = blob?.url || '';
}
};This is the pattern the React Compiler is designed for — imperative ref reads wrapped in callbacks, not inline in handlers. Option 3: Disable the rule for the file if you get many false positives /* eslint-disable react-compiler/react-compiler */Why the rule fires here but not alwaysThe React Compiler's lint rule does static analysis and flags |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
A linting error I am getting-
Here is the component-
I am not calling ref during render time. Its on a
onSubmithandler. Is onSubmit will call render time.All reactions