Skip to content

Commit e870e23

Browse files
committed
fix: refactor ref to support react 18
1 parent fc1e98f commit e870e23

4 files changed

Lines changed: 1630 additions & 46 deletions

File tree

packages/react-qr-code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"react-dom": "^19.0.0",
5959
"typescript": "~5.7.3",
6060
"typescript-eslint": "^8.25.0",
61-
"vite": "^6.1.1",
61+
"vite": "^6.2.0",
6262
"vite-plugin-dts": "^4.5.0"
6363
}
6464
}

packages/react-qr-code/src/react-qr-code.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useImperativeHandle, useRef } from 'react'
1+
import { forwardRef, useImperativeHandle, useRef } from 'react'
22

33
import { Background } from './components/background'
44
import { DataModules } from './components/data-modules'
@@ -13,13 +13,12 @@ import {
1313
} from './constants'
1414
import { useIds } from './hooks/use-ids'
1515
import { useQRCode } from './hooks/use-qr-code'
16-
import type { DownloadOptions, ReactQRCodeProps } from './types/lib'
16+
import type { DownloadOptions, ReactQRCodeProps, ReactQRCodeRef } from './types/lib'
1717
import { downloadRaster, downloadSVG } from './utils/download'
1818
import { excavateModules } from './utils/qr-code'
1919

20-
const ReactQRCode = (props: ReactQRCodeProps) => {
20+
const ReactQRCode = forwardRef<ReactQRCodeRef, ReactQRCodeProps>((props, ref) => {
2121
const {
22-
ref,
2322
value,
2423
size = DEFAULT_SIZE,
2524
level = DEFAULT_LEVEL,
@@ -125,7 +124,7 @@ const ReactQRCode = (props: ReactQRCodeProps) => {
125124
{image}
126125
</svg>
127126
)
128-
}
127+
})
129128

130129
ReactQRCode.displayName = 'ReactQRCode'
131130

packages/react-qr-code/src/types/lib.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export interface ReactQRCodeRef {
109109
}
110110

111111
export interface ReactQRCodeProps {
112-
ref?: React.Ref<ReactQRCodeRef>
113112
/**
114113
* The value to encode into the QR Code. An array of strings can be passed in
115114
* to represent multiple segments to further optimize the QR Code.

0 commit comments

Comments
 (0)