# � FX React Plugin - Complete Cheat Sheet ## <� **Plugin Overview** **FX React** provides seamless integration between React and FX, offering reactive hooks that automatically sync with FX nodes. No Redux, no context drilling, no manual state management - just pure reactive React with FX. ### **Core Features** -  **Reactive Hooks** - `useFX`, `useFXState` auto-update with FX nodes -  **Zero Boilerplate** - No actions, reducers, or dispatchers needed -  **Form Management** - `useFXForm` with validation and FX sync -  **API Integration** - `useFXAPI` with loading/error states -  **Lifecycle Hooks** - Component registration with FX -  **Caching Support** - `useFXCache` with FX cache integration -  **Context Provider** - `FXProvider` for React component trees --- ## =� **Installation & Setup** ### **Loading the Plugin** ```html ``` ### **React Component Setup** ```tsx import React from 'react'; // Hooks are available globally or via import const { useFX, useFXState } = FXReact; function MyApp() { // FX node automatically updates component const appTitle = useFX('app.title', 'Default Title'); return

{appTitle}

; } ``` --- ## <� **Core Hooks Reference** ### **useFX - Reactive State Reading** ```tsx const value = useFX(path, defaultValue) ``` | Parameter | Type | Description | |-----------|------|-------------| | `path` | `string` | FX node path | | `defaultValue` | `any` | Default value if node doesn't exist | **Examples:** ```tsx function UserProfile() { // Basic usage const userName = useFX('user.name', 'Anonymous'); const userEmail = useFX('user.email'); // Complex objects const userProfile = useFX('user.profile', { avatar: '/default-avatar.png', bio: 'No bio available' }); // Arrays const notifications = useFX('user.notifications', []); return (

{userName}

{userEmail}

Avatar

{userProfile.bio}

{notifications.length} notifications
); } ``` ### **useFXState - Two-Way Reactive Binding** ```tsx const [value, setValue] = useFXState(path, defaultValue) ``` **Examples:** ```tsx function SettingsForm() { const [username, setUsername] = useFXState('settings.username', ''); const [theme, setTheme] = useFXState('settings.theme', 'light'); const [notifications, setNotifications] = useFXState('settings.notifications', true); return (
setUsername(e.target.value)} placeholder="Username" />
); } // Changes automatically sync with FX nodes: // $$('settings.username').get() === current username // $$('settings.theme').get() === current theme ``` ### **useFXSetter - Write-Only Hook** ```tsx const setValue = useFXSetter(path) ``` **Examples:** ```tsx function ActionButtons() { const setCounter = useFXSetter('app.counter'); const setMessage = useFXSetter('app.message'); const setUserStatus = useFXSetter('user.status'); return (
); } ``` ### **useFXNode - Direct Node Access** ```tsx const node = useFXNode(path) ``` **Examples:** ```tsx function AdvancedComponent() { const userNode = useFXNode('user.profile'); const handleComplexUpdate = () => { if (userNode) { // Direct node operations userNode.set({ ...userNode.get(), lastActive: Date.now(), sessionCount: (userNode.get()?.sessionCount || 0) + 1 }); } }; return ( ); } ``` --- ## =� **Form Management with useFXForm** ### **Basic Form Hook** ```tsx const form = useFXForm(initialValues, options) ``` **Options:** | Option | Type | Description | |--------|------|-------------| | `fxPath` | `string` | FX node to sync form data | | `validate` | `function` | Validation function | | `onSubmit` | `function` | Submit handler | ### **Simple Form Example** ```tsx function ContactForm() { const form = useFXForm( { name: '', email: '', message: '' }, { fxPath: 'forms.contact', validate: (values) => { const errors = {}; if (!values.name) errors.name = 'Name is required'; if (!values.email.includes('@')) errors.email = 'Invalid email'; return errors; }, onSubmit: async (values) => { const response = await fetch('/api/contact', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(values) }); if (!response.ok) throw new Error('Failed to submit'); alert('Message sent!'); } } ); return (
form.setValue('name', e.target.value)} /> {form.errors.name && {form.errors.name}}
form.setValue('email', e.target.value)} /> {form.errors.email && {form.errors.email}}