Add components
A component is UI the AI shows during a chat. Build things you want to show, like a status window, an inventory, or choices, and the AI calls them when needed. You can make one without knowing code by using Create with Google AI Studio.
This is the Expert mode guide. For Simple mode, see Lorebook, components, and optional items.
Add a component
- Select Add component.
- Paste the code into the JSX code field. Select Paste to put in the code on your clipboard.
- Check in the preview how it will look in a chat.
The component name and props are read from the code automatically.
- JSX code: Code in the form
function Name({ prop = default }). Code fences and import statements are cleaned up automatically. You can write up to 20,000 characters. - Default prop values: Shows the props read from the code and their defaults. The defaults become examples of what the AI fills in, and the preview uses them too.
- Call tag: The tag under "This is how the AI calls it in chat." Select Copy and paste it into the Prompt tab.
Here is the status window code for the example work. It needs a function name (StatusWindow) and at least one prop (hp, mp).
function StatusWindow({ hp = 100, mp = 40 }) {
const bar = (value, color) => (
<div className="h-2 w-full rounded-full bg-slate-700">
<div className={`h-2 rounded-full ${color}`} style={{ width: `${Math.max(0, Math.min(100, value))}%` }} />
</div>
);
return (
<div className="my-2 w-full max-w-sm rounded-xl border border-cyan-400/40 bg-slate-900/90 p-3 text-slate-100">
<div className="mb-2 flex items-center justify-between text-[11px] font-bold tracking-widest text-cyan-300">
<span>STATUS</span>
<span>Quarantine B-3</span>
</div>
<div className="space-y-2 text-sm">
<div>
<div className="mb-1 flex justify-between"><span>HP</span><span>{hp}/100</span></div>
{bar(hp, "bg-rose-400")}
</div>
<div>
<div className="mb-1 flex justify-between"><span>MP</span><span>{mp}/100</span></div>
{bar(mp, "bg-sky-400")}
</div>
</div>
</div>
);
}
Connect it to the prompt
Adding a component alone doesn't tell the AI when to call it. Write when to call it in the Prompt tab.
- Basic: In Component output rules, write when each component appears. The tag is added automatically, exactly as it appears in the Components tab (
<StatusWindow hp={100} mp={40} />), together with the rule sentence. Example:When a battle starts and when HP changes. hp = health, mp = mana. - Write it myself: You write the call tag, when it appears, and what the props mean. You can paste the tag you copied with Copy in the Components tab as is, or write
{value}where the value goes.
With Write it myself, write it like this.
### Component output rules
At the moment a rule applies, output the tag below on its own line, exactly as written.
- `<StatusWindow hp={value} mp={value} />`: when a battle starts and when HP changes. hp = health, mp = mana.
A component only draws the values the AI gives it. Whether the values are right, like an HP calculation, depends on the AI's reply. Even with rules, the AI may occasionally leave out the tag or fill in values differently.
Create with AI Studio
You can make a component by chatting with Gemini, even without knowing code. Start from Create with Google AI Studio at the top of the Components tab.
- Select Copy work info. Your work's settings, image addresses, and current description are copied together.
- Select Open Google AI Studio. If it's your first time, make your own workspace with Remix.
- Paste the work info into the input, add a line or two about what you want below it, and send.
- When it's done, select MYMI에 붙여넣을 코드 복사 (Copy code for MYMI), and paste it into the Add component → JSX code field in MYMI.
- Copy the sentence in Gemini's reply that says when to show it, and paste it into the Prompt tab. With Basic, put it in that component's field under Component output rules.
Select How to use to open step-by-step instructions. To see the actual AI Studio screens, go to Follow along in Google AI Studio.
You can use it within your Google account's free request allowance. No payment or API key is needed.
Components that use images
- To let the AI choose an image for each scene, have the component take the image as a prop, and in the prompt write the whole value as an asset path, like
img="{{URL}}/A/1.webp". If you put it among other text, likeurl({{URL}}/…), it isn't replaced with an address. - If you write a path that doesn't exist, an empty value goes in. Build the component so it draws only when the image value exists.
- Don't use
{{URL}}in a prop's default value. Use a real image address (starting with https) or an empty value. - An image address written directly in the code stops showing if you delete that asset.
If you get stuck
It says "Some components have no function name."
Check that the code starts in the form function Name(...). Arrow functions and anonymous functions have no readable name.
It says "Some components have no props. Declare at least one prop."
You need to declare at least one prop that the function takes. Example: function StatusWindow({ hp = 100 })
I changed the code, but the default prop values stayed the same
When you replace all the code with the Paste button, the defaults are read again. If you edit the code field a little at a time, the earlier defaults stay, so check Default prop values after you edit.
I selected a button in the preview, but no message was sent
The preview in the creation screen is only for checking how it looks, so nothing is sent to a real chat. After you publish, start a chat with View work on the complete screen to check. To test before other users see it, set Visibility to Private and publish.
