Remove Button error boundary (#3372)

zio/stable
dan 2024-04-03 19:11:29 +01:00 committed by GitHub
parent 75c9da931c
commit 75d6535402
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 41 deletions

View File

@ -14,7 +14,6 @@ import {
import LinearGradient from 'react-native-linear-gradient'
import {Trans} from '@lingui/macro'
import {logger} from '#/logger'
import {android, atoms as a, flatten, tokens, useTheme} from '#/alf'
import {Props as SVGIconProps} from '#/components/icons/common'
import {normalizeTextStyles} from '#/components/Typography'
@ -405,7 +404,6 @@ export function Button({
</View>
)}
<Context.Provider value={context}>
<ButtonTextErrorBoundary>
{/* @ts-ignore */}
{typeof children === 'string' || children?.type === Trans ? (
/* @ts-ignore */
@ -415,41 +413,11 @@ export function Button({
) : (
children
)}
</ButtonTextErrorBoundary>
</Context.Provider>
</Pressable>
)
}
export class ButtonTextErrorBoundary extends React.Component<
React.PropsWithChildren<{}>,
{hasError: boolean; error: Error | undefined}
> {
public state = {
hasError: false,
error: undefined,
}
public static getDerivedStateFromError(error: Error) {
return {hasError: true, error}
}
public componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
logger.error('ButtonTextErrorBoundary caught an error', {
message: error.message,
errorInfo,
})
}
public render() {
if (this.state.hasError) {
return <ButtonText>ERROR</ButtonText>
}
return this.props.children
}
}
export function useSharedButtonTextStyles() {
const t = useTheme()
const {color, variant, disabled, size} = useButtonContext()