Repository navigation
Commit 2df0b47
feat(jsx): add React-compatible overloads to useRef (#5063)
* feat(jsx): add React-compatible overloads to useRef
Adds overloads so that useRef returns a non-nullable ref when given a
non-null initial value, matching React's API.
- useRef<T>(initialValue: T): MutableRefObject<T>
- useRef<T>(initialValue: T | null): RefObject<T>
- useRef<T = undefined>(): MutableRefObject<T | undefined>
This is a type-only change; the runtime implementation is unchanged.
Closes #5056
* feat(jsx)!: align RefObject and useRef with React 19
- `RefObject<T>` now has non-null mutable `current`
- `MutableRefObject<T>` becomes a deprecated alias
- `useRef` overloads match React 19; zero-arg form removed in favor of
`useRef(undefined)`
- `createRef`, `forwardRef`, `useImperativeHandle` updated to use
`RefObject<T | null>` for nullable refs
BREAKING CHANGE: `RefObject<T>` was `{ current: T | null }`; nullable
refs should now be typed as `RefObject<T | null>`. `useRef()` with no
argument no longer type-checks; pass `undefined` explicitly.
* ci: apply automated fixes
* refactor(jsx): remove MutableRefObject alias
hono/jsx has never exposed MutableRefObject before, and React 19 marks
it as deprecated. Per PR discussion, drop the alias entirely instead of
keeping a deprecated re-export.
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>1 parent 3bc96ba commit 2df0b47
3 files changed
Lines changed: 43 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1905 | 1905 | | |
1906 | 1906 | | |
1907 | 1907 | | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
1908 | 1927 | | |
1909 | | - | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
1910 | 1935 | | |
1911 | 1936 | | |
1912 | 1937 | | |
| |||
2015 | 2040 | | |
2016 | 2041 | | |
2017 | 2042 | | |
2018 | | - | |
| 2043 | + | |
2019 | 2044 | | |
2020 | 2045 | | |
2021 | 2046 | | |
| |||
2115 | 2140 | | |
2116 | 2141 | | |
2117 | 2142 | | |
2118 | | - | |
| 2143 | + | |
2119 | 2144 | | |
2120 | 2145 | | |
2121 | 2146 | | |
| |||
2229 | 2254 | | |
2230 | 2255 | | |
2231 | 2256 | | |
2232 | | - | |
| 2257 | + | |
2233 | 2258 | | |
2234 | 2259 | | |
2235 | 2260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
| 323 | + | |
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
| 395 | + | |
396 | 396 | | |
397 | 397 | | |
398 | 398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
318 | | - | |
319 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
320 | 324 | | |
321 | 325 | | |
322 | | - | |
| 326 | + | |
323 | 327 | | |
324 | 328 | | |
325 | 329 | | |
| |||
368 | 372 | | |
369 | 373 | | |
370 | 374 | | |
371 | | - | |
| 375 | + | |
372 | 376 | | |
373 | 377 | | |
374 | 378 | | |
375 | 379 | | |
376 | | - | |
377 | | - | |
| 380 | + | |
| 381 | + | |
378 | 382 | | |
379 | 383 | | |
380 | 384 | | |
381 | 385 | | |
382 | 386 | | |
383 | 387 | | |
384 | 388 | | |
385 | | - | |
| 389 | + | |
386 | 390 | | |
387 | 391 | | |
388 | 392 | | |
| |||
0 commit comments