Skip to content

Commit 89b6f6f

Browse files
committed
fix(badge): make action, variant and size reactive to state changes
Previously, the Badge component did not update its visual state when the `action`, `variant`, or `size` props were driven by React state. This happened because `withStyleContext` memoized context values and did not trigger a re-render for style context consumers.
1 parent 94c970d commit 89b6f6f

File tree

1 file changed

+8
-6
lines changed
  • apps/starter-kit-next/components/ui/badge

1 file changed

+8
-6
lines changed

apps/starter-kit-next/components/ui/badge/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use client';
2-
import React from 'react';
2+
import React, { useMemo } from 'react';
33
import { Text, View } from 'react-native';
44
import { PrimitiveIcon, UIIcon } from '@gluestack-ui/core/icon/creator';
55
import { tva } from '@gluestack-ui/utils/nativewind-utils';
@@ -120,15 +120,17 @@ function Badge({
120120
className,
121121
...props
122122
}: { className?: string } & IBadgeProps) {
123+
124+
const contextValue = useMemo(
125+
() => ({ action, variant, size }),
126+
[action, variant, size]
127+
);
128+
123129
return (
124130
<ContextView
125131
className={badgeStyle({ action, variant, class: className })}
126132
{...props}
127-
context={{
128-
action,
129-
variant,
130-
size,
131-
}}
133+
context={contextValue}
132134
>
133135
{children}
134136
</ContextView>

0 commit comments

Comments
 (0)