Skip to content

Commit 0ca6b76

Browse files
fix: do not spawn additional stores inside variant
1 parent a91fb94 commit 0ca6b76

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/core/variant.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ export function variantFactory(context: Context) {
3838

3939
// Shortcut for Store<boolean>
4040
if ('if' in config) {
41-
$case = config.if.map((value): Variant => (value ? 'then' : 'else') as Variant);
42-
41+
$case = config.if as any;
4342
cases = {
4443
then: config.then,
4544
else: config.else,
@@ -54,7 +53,10 @@ export function variantFactory(context: Context) {
5453
}
5554

5655
function View(props: Props) {
57-
const nameOfCase = context.useUnit($case, config.useUnitConfig);
56+
const nameOfCaseRaw = context.useUnit($case, config.useUnitConfig);
57+
const nameOfCase = (
58+
'if' in config ? ifToVariant(nameOfCaseRaw as any) : nameOfCaseRaw
59+
) as Variant;
5860
const Component = cases[nameOfCase] ?? def;
5961

6062
return React.createElement(Component as any, props as any);
@@ -70,3 +72,7 @@ export function variantFactory(context: Context) {
7072
}) as unknown as (p: Props) => React.ReactNode;
7173
};
7274
}
75+
76+
function ifToVariant(value: boolean): 'then' | 'else' {
77+
return value ? 'then' : 'else';
78+
}

0 commit comments

Comments
 (0)