Working with AI Assistants
This guide helps developers use AI coding assistants effectively with Valdi.
🚨 Critical: Valdi is NOT React
The most important thing to know when using AI assistants with Valdi: despite using TSX/JSX syntax, Valdi is fundamentally different from React.
AI models are heavily trained on React and will often suggest React patterns that don't exist in Valdi. This guide will help you recognize and correct these suggestions.
Common AI Hallucinations
1. useState Hook (Doesn't Exist)
AI might suggest:
// ❌ WRONG - useState doesn't exist in Valdi
const [count, setCount] = useState(0);
Correct Valdi pattern:
// ✅ CORRECT - Use StatefulComponent with setState()
import { StatefulComponent } from 'valdi_core/src/Component';
class Counter extends StatefulComponent<ViewModel, State> {
state = { count: 0 };
incrementCount = () => {
this.setState({ count: this.state.count + 1 }); // setState auto re-renders
};
onRender() {
<view onTap={this.incrementCount}>
<label value={`Count: ${this.state.count}`} />
</view>;
}
}
2. useEffect Hook (Doesn't Exist)
AI might suggest:
// ❌ WRONG - useEffect doesn't exist in Valdi
useEffect(() => {
fetchData();
}, []);
Correct Valdi pattern:
// ✅ CORRECT - Use lifecycle methods
import { StatefulComponent } from 'valdi_core/src/Component';
class DataComponent extends StatefulComponent<ViewModel, State> {
state = { data: null };
onCreate() {
this.fetchData();
}
onViewModelUpdate(prevViewModel: ViewModel) {
if (this.viewModel.id !== prevViewModel.id) {
this.fetchData();
}
}
async fetchData() {
const data = await fetch(...);
this.setState({ data });
}
}
3. Functional Components (Don't Exist)
AI might suggest:
// ❌ WRONG - Functional components don't exist in Valdi
const Button = ({ title, onTap }) => {
return <view onTap={onTap}><label value={title} /></view>;
};
Correct Valdi pattern:
// ✅ CORRECT - Use class-based components
import { Component } from 'valdi_core/src/Component';
interface ButtonViewModel {
title: string;
onTap: () => void;
}
class Button extends Component<ButtonViewModel> {
onRender() {
<view onTap={this.viewModel.onTap}>
<label value={this.viewModel.title} />
</view>;
}
}
4. Returning JSX from onRender()
AI might suggest:
// ❌ WRONG - onRender returns void, not JSX
class MyComponent extends Component {
onRender() {
return <view />; // Compiler error!
}
}
Correct Valdi pattern:
// ✅ CORRECT - JSX is a statement, onRender returns void
class MyComponent extends Component {
onRender() {
<view />; // No return statement
}
}
5. useContext Hook (Doesn't Exist)
AI might suggest:
// ❌ WRONG - useContext doesn't exist in Valdi
const theme = useContext(ThemeContext);
Correct Valdi pattern:
// ✅ CORRECT - Use Provider pattern with HOC
import { createProviderComponentWithKeyName } from 'valdi_core/src/provider/createProvider';
import { withProviders } from 'valdi_core/src/provider/withProviders';
import { ProvidersValuesViewModel } from 'valdi_core/src/provider/withProviders';
import { Component } from 'valdi_core/src/Component';
// Define theme service
class Theme {
primary = '#FFFC00';
}
// Create provider
const ThemeProvider = createProviderComponentWithKeyName<Theme>('ThemeProvider');
// Provide value
class AppRoot extends Component {
private theme = new Theme();
onRender() {
<ThemeProvider value={this.theme}>
<ThemedComponentWithProvider />
</ThemeProvider>;
}
}
// Consume with HOC
interface ThemedViewModel extends ProvidersValuesViewModel<[Theme]> {}
class ThemedComponent extends Component<ThemedViewModel> {
onRender() {
const [theme] = this.viewModel.providersValues;
<view backgroundColor={theme.primary} />;
}
}
const ThemedComponentWithProvider = withProviders(ThemeProvider)(ThemedComponent);
How to Prompt AI Assistants
Good Prompts
When asking AI for help, be explicit that you're using Valdi:
✅ "In Valdi (not React), how do I add state to a component?"
✅ "Using Valdi's class-based component model, how do I fetch data on mount?"
✅ "How do I trigger a re-render in Valdi after updating state?"
Prompts to Avoid
❌ "How do I add a counter?" (AI will assume React)
❌ "Create a functional component" (Doesn't exist in Valdi)
❌ "Use hooks to manage state" (Hooks don't exist in Valdi)
Quick Reference: React vs Valdi
| Concept | React Pattern | Valdi Pattern |
|---|---|---|
| Component | const C = () => {} | class C extends StatefulComponent {} |
| State | useState(0) | state = { count: 0 } |
| Update State | setCount(1) | this.setState({ count: 1 }) |
| Props | props.title | this.viewModel.title |
| Mount effect | useEffect(() => {}, []) | onCreate() {} |
| Update effect | useEffect(() => {}, [dep]) | onViewModelUpdate(prev) {} |
| Unmount effect | useEffect(() => () => {}, []) | onDestroy() {} |
| Context | useContext(Ctx) | withProviders(Provider)(Component) + this.viewModel.providersValues |
| Render | return <view /> | <view />; // statement, returns void |
Setting Up AI Tools
Quick Setup with valdi skills
The fastest way to configure any AI tool for Valdi development is the valdi skills command. It installs Valdi-specific context files (bundled in the npm package) into whichever AI tools you have:
# Auto-detects Claude Code, Cursor, and Copilot — installs all skills for each
valdi skills install
# See what's available and what's already installed
valdi skills list
# Keep skills up to date
valdi skills update
Skills cover TSX patterns, Bazel, iOS/Android integration, async lifecycle, performance, testing, and more. See ai-skills/CONTRIBUTING_SKILLS.md to contribute a new skill.
Cursor
Use valdi skills install --for=cursor to install skills to ~/.cursor/skills/. Skills activate automatically based on description when you work on Valdi projects.
GitHub Copilot
Add this to your workspace settings:
{
"github.copilot.chat.codeGeneration.instructions": [
{
"text": "This is a Valdi project, not React. Use class-based components extending StatefulComponent (with state) or Component (stateless). State is managed via StatefulComponent with this.setState(). Lifecycle methods are onCreate(), onViewModelUpdate(previousViewModel), onDestroy(). Props are accessed via this.viewModel. The onRender() method returns void."
}
]
}
Claude Code
Run valdi skills install --for=claude to install Valdi skills globally into Claude Code (~/.claude/skills/). Skills activate automatically when you work on Valdi projects in any directory.
For one-off conversations without skills installed, include this in your first message:
"I'm working with Valdi, a cross-platform UI framework that uses TSX syntax but is NOT React. Valdi uses class-based components (StatefulComponent with setState() for state, or Component for stateless), not functional components or hooks. Props are accessed via this.viewModel. Lifecycle methods are onCreate(), onViewModelUpdate(), and onDestroy(). The onRender() method returns void, with JSX written as statements."
ChatGPT
When starting a conversation, include the same context as the Claude one-off prompt above.
Reviewing AI Suggestions
Always check AI-generated code for these red flags:
🚩 Imports from 'react' - Valdi imports from 'valdi_core'
🚩 Hooks (useState, useEffect, etc.) - Don't exist in Valdi
🚩 Functional components - Must be class-based
🚩 Return statements in onRender() - Should return void
🚩 Using this.props - Should be this.viewModel
🚩 Using markNeedsRender() - Doesn't exist, use setState() instead
🚩 Lifecycle methods like onMount/onUnmount - Should be onCreate/onDestroy
🚩 this.context.get() - Doesn't exist, use withProviders() HOC pattern
Resources
- AGENTS.md - Comprehensive guide for AI assistants
- Getting Started - Learn Valdi basics
- API Reference - Complete API documentation
Getting Help
If AI tools are consistently giving incorrect suggestions:
- Install skills: Run
valdi skills installto give your AI tool Valdi context - Be explicit: Mention "Valdi (not React)" in your prompts
- Report issues: Open an issue if patterns are consistently wrong
- Ask the community: Post in GitHub Discussions for help
Remember: AI assistants are trained primarily on React code. When working with Valdi, you're the domain expert guiding the AI, not the other way around!