fix: workflow page throw warning: Attempts to access this ref will fail (#12166)
This commit is contained in:
parent
89ce9a5db2
commit
eb8963a673
1 changed files with 52 additions and 49 deletions
|
|
@ -11,7 +11,9 @@ type SwitchProps = {
|
||||||
className?: string
|
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)
|
const [enabled, setEnabled] = useState(defaultValue)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setEnabled(defaultValue)
|
setEnabled(defaultValue)
|
||||||
|
|
@ -38,6 +40,7 @@ const Switch = ({ onChange, size = 'md', defaultValue = false, disabled = false,
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<OriginalSwitch
|
<OriginalSwitch
|
||||||
|
ref={propRef}
|
||||||
checked={enabled}
|
checked={enabled}
|
||||||
onChange={(checked: boolean) => {
|
onChange={(checked: boolean) => {
|
||||||
if (disabled)
|
if (disabled)
|
||||||
|
|
@ -63,7 +66,7 @@ const Switch = ({ onChange, size = 'md', defaultValue = false, disabled = false,
|
||||||
/>
|
/>
|
||||||
</OriginalSwitch>
|
</OriginalSwitch>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|
||||||
Switch.displayName = 'Switch'
|
Switch.displayName = 'Switch'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue