fix: workflow page throw warning: Attempts to access this ref will fail (#12166)

This commit is contained in:
NFish 2024-12-27 18:33:15 +08:00 committed by GitHub
parent 89ce9a5db2
commit eb8963a673
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,7 +11,9 @@ type SwitchProps = {
className?: string
}
const Switch = ({ onChange, size = 'md', defaultValue = false, disabled = false, className }: SwitchProps) => {
const Switch = React.forwardRef(
({ onChange, size = 'md', defaultValue = false, disabled = false, className }: SwitchProps,
propRef: React.Ref<HTMLButtonElement>) => {
const [enabled, setEnabled] = useState(defaultValue)
useEffect(() => {
setEnabled(defaultValue)
@ -38,6 +40,7 @@ const Switch = ({ onChange, size = 'md', defaultValue = false, disabled = false,
}
return (
<OriginalSwitch
ref={propRef}
checked={enabled}
onChange={(checked: boolean) => {
if (disabled)
@ -63,7 +66,7 @@ const Switch = ({ onChange, size = 'md', defaultValue = false, disabled = false,
/>
</OriginalSwitch>
)
}
})
Switch.displayName = 'Switch'