From 2cbad54ced445910378d414b044fdb47ee3471ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Fri, 11 Jul 2025 06:49:18 +0200 Subject: [PATCH] Memo --- packages/effect-fc/src/Component.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/effect-fc/src/Component.ts b/packages/effect-fc/src/Component.ts index d7ff100..1ca3411 100644 --- a/packages/effect-fc/src/Component.ts +++ b/packages/effect-fc/src/Component.ts @@ -1,4 +1,4 @@ -import { Context, Effect, ExecutionStrategy, Function, Pipeable, Runtime, Scope, String, Tracer, type Utils } from "effect" +import { Context, Effect, type Equivalence, ExecutionStrategy, Function, Pipeable, Runtime, Scope, String, Tracer, type Utils } from "effect" import * as React from "react" import * as Hook from "./Hook.js" import type { ExcludeKeys } from "./utils.js" @@ -61,6 +61,27 @@ export const make = < } +export interface Memoized

{ + readonly memo: true + readonly propsAreEqual?: Equivalence.Equivalence

+} + +export const memo: { + ( + context: React.Context>, + ): (self: Component) => React.FC

+ ( + self: Component, + context: React.Context>, + ): React.FC

+} = Function.dual(2, ( + self: Component, + context: React.Context>, +): React.FC

=> { + +}) + + export const useFC: { ( self: Component @@ -99,7 +120,7 @@ export const useSuspenseFC: { never, Exclude > -} = Effect.fn("useSuspenseFC")(function* ( +} = Effect.fn("useSuspenseFC")(function* >( self: Component ) { const runtimeRef = React.useRef>>(null!)