1
+
2
+## Input
3
+
4
+```javascript
5
+// @enableInferEventHandlers
6
+import {useRef} from 'react';
7
+
8
+// Simulates react-hook-form's handleSubmit
9
+function handleSubmit<T>(callback: (data: T) => void | Promise<void>) {
10
+ return (event: any) => {
11
+ event.preventDefault();
12
+ callback({} as T);
13
+ };
14
+}
15
+
16
+// Simulates an upload function
17
+async function upload(file: any): Promise<{blob: {url: string}}> {
18
+ return {blob: {url: 'https://example.com/file.jpg'}};
19
+}
20
+
21
+interface SignatureRef {
22
+ toFile(): any;
23
+}
24
+
25
+function Component() {
26
+ const ref = useRef<SignatureRef>(null);
27
+
28
+ const onSubmit = async (value: any) => {
29
+ // This should be allowed: accessing ref.current in an async event handler
30
+ // that's wrapped and passed to onSubmit prop
31
+ let sigUrl: string;
32
+ if (value.hasSignature) {
33
+ const {blob} = await upload(ref.current?.toFile());
34
+ sigUrl = blob?.url || '';
35
+ } else {
36
+ sigUrl = value.signature;
37
+ }
38
+ console.log('Signature URL:', sigUrl);
39
+ };
40
+
41
+ return (
42
+ <form onSubmit={handleSubmit(onSubmit)}>
43
+ <input type="text" name="signature" />
44
+ <button type="submit">Submit</button>
45
+ </form>
46
+ );
47
+}
48
+
49
+export const FIXTURE_ENTRYPOINT = {
50
+ fn: Component,
51
+ params: [{}],
52
+};
53
+
54
+```
55
+
56
+## Code
57
+
58
+```javascript
59
+import { c as _c } from "react/compiler-runtime"; // @enableInferEventHandlers
60
+import { useRef } from "react";
61
+
62
+// Simulates react-hook-form's handleSubmit
63
+function handleSubmit(callback) {
64
+ const $ = _c(2);
65
+ let t0;
66
+ if ($[0] !== callback) {
67
+ t0 = (event) => {
68
+ event.preventDefault();
69
+ callback({} as T);
70
+ };
71
+ $[0] = callback;
72
+ $[1] = t0;
73
+ } else {
74
+ t0 = $[1];
75
+ }
76
+ return t0;
77
+}
78
+
79
+// Simulates an upload function
80
+async function upload(file) {
81
+ const $ = _c(1);
82
+ let t0;
83
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
84
+ t0 = { blob: { url: "https://example.com/file.jpg" } };
85
+ $[0] = t0;
86
+ } else {
87
+ t0 = $[0];
88
+ }
89
+ return t0;
90
+}
91
+
92
+interface SignatureRef {
93
+ toFile(): any;
94
+}
95
+
96
+function Component() {
97
+ const $ = _c(4);
98
+ const ref = useRef(null);
99
+
100
+ const onSubmit = async (value) => {
101
+ let sigUrl;
102
+ if (value.hasSignature) {
103
+ const { blob } = await upload(ref.current?.toFile());
104
+ sigUrl = blob?.url || "";
105
+ } else {
106
+ sigUrl = value.signature;
107
+ }
108
+
109
+ console.log("Signature URL:", sigUrl);
110
+ };
111
+
112
+ const t0 = handleSubmit(onSubmit);
113
+ let t1;
114
+ let t2;
115
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
116
+ t1 = <input type="text" name="signature" />;
117
+ t2 = <button type="submit">Submit</button>;
118
+ $[0] = t1;
119
+ $[1] = t2;
120
+ } else {
121
+ t1 = $[0];
122
+ t2 = $[1];
123
+ }
124
+ let t3;
125
+ if ($[2] !== t0) {
126
+ t3 = (
127
+ <form onSubmit={t0}>
128
+ {t1}
129
+ {t2}
130
+ </form>
131
+ );
132
+ $[2] = t0;
133
+ $[3] = t3;
134
+ } else {
135
+ t3 = $[3];
136
+ }
137
+ return t3;
138
+}
139
+
140
+export const FIXTURE_ENTRYPOINT = {
141
+ fn: Component,
142
+ params: [{}],
143
+};
144
+
145
+```
146
+
147
+### Eval output
148
+(kind: ok) <form><input type="text" name="signature"><button type="submit">Submit</button></form>
\ No newline at end of file