Skip to main content

Module: core/memoize

Variables

isMemoizedSymbol

Const isMemoizedSymbol: typeof isMemoizedSymbol

Defined in

packages/ai-jsx/src/core/memoize.tsx:6

Functions

memo

memo(renderable): Node

Memoize a Renderable so it always returns the same thing.

For example, imagine you have the following:

   const catName = (
<ChatCompletion>
<UserMessage>Give me a cat name</UserMessage>
</ChatCompletion>
);

<ChatCompletion>
<UserMessage>
I have a cat named {catName}. Tell me a story about {catName}.
</UserMessage>
</ChatCompletion>

In this case, catName will result in two separate model calls, so you'll get two different cat names.

If this is not desired, you can wrap the component in memo:

   const catName = memo(<ChatCompletion>
<UserMessage>Give me a cat name</UserMessage>
</ChatCompletion>);

<ChatCompletion>
<UserMessage>
I have a cat named {catName}. Tell me a story about {catName}.
</UserMessage>
</ChatCompletion>

Now, catName will result in a single model call, and its value will be reused everywhere that component appears in the tree.

The memoization is fully recursive.

Parameters

NameType
renderableRenderable

Returns

Node

Defined in

packages/ai-jsx/src/core/memoize.tsx:45