### Create a Simple Reactive Anchor Component Source: https://github.com/beerush-id/anchor/blob/main/docs/react/getting-started.md Demonstrates creating a basic Anchor component using `setup()`, `mutable()`, and `render()`. The `setup` function defines the component's state (`mutable`) and logic, while `render` defines the reactive UI. The example shows a counter that increments on button click. ```tsx import { setup, mutable, render } from '@anchorlib/react'; // ━━━ COMPONENT (Logic Layer) ━━━ export const Counter = setup(() => { const state = mutable({ count: 0 }); // ━━━ VIEW (Presentation Layer) ━━━ return render(() => ( )); }); ``` -------------------------------- ### Install Anchor React Library Source: https://github.com/beerush-id/anchor/blob/main/docs/react/getting-started.md Installs the Anchor React library using npm. This is the first step to integrating Anchor into your React project. ```bash npm install @anchorlib/react ``` -------------------------------- ### Full Migration to setup() with TodoApp Example Source: https://github.com/beerush-id/anchor/blob/main/docs/react/ai-knowledge-base.md Demonstrates converting a React component to use Anchor.js's setup() function for complete stability. It includes mutable state for form input and todos, and uses snippets for reusable UI parts like the TodoForm and TodoList. This pattern enhances stability by managing state and logic within a stable function scope. ```tsx export const TodoApp = setup(() => { const formState = mutable({ text: '' }); const todos = mutable([]); const handleSubmit = () => { todos.push({ text: formState.text }); formState.text = ''; }; const TodoForm = snippet(() => ( formState.text = e.target.value} /> )); const TodoList = snippet(() => (
Count: {state.count}
Loading...
} {user.status === 'error' &&Error: {user.error?.message}
} {user.status === 'success' &&Hello, {user.data.name}!
}Count: {count.value}
Doubled: {doubled.value}
> )); return (Total clicks: {total}
Role: {user.role}
{user.data.email}
Loading user...
} {user.status === 'error' &&Error: {user.error?.message}
} {user.status === 'success' && ( <>Loading posts...
} {posts.status === 'success' &&