Skip to content

Commit

Permalink
Remove Button error boundary (#3372)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Apr 3, 2024
1 parent 75c9da9 commit 75d6535
Showing 1 changed file with 9 additions and 41 deletions.
50 changes: 9 additions & 41 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -405,51 +404,20 @@ export function Button({
</View>
)}
<Context.Provider value={context}>
<ButtonTextErrorBoundary>
{/* @ts-ignore */}
{typeof children === 'string' || children?.type === Trans ? (
/* @ts-ignore */
<ButtonText>{children}</ButtonText>
) : typeof children === 'function' ? (
children(context)
) : (
children
)}
</ButtonTextErrorBoundary>
{/* @ts-ignore */}
{typeof children === 'string' || children?.type === Trans ? (
/* @ts-ignore */
<ButtonText>{children}</ButtonText>
) : typeof children === 'function' ? (
children(context)
) : (
children
)}
</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()
Expand Down

0 comments on commit 75d6535

Please sign in to comment.