Component Rendering
Remix components follow a two-phase rendering model: setup once, then render on every update.Component Lifecycle
First Render
- Component function is called with
handleandsetupprop - Setup phase runs once to initialize state
- Returned render function is stored
- Render function is called with props
- Queued tasks execute after rendering
Subsequent Updates
- Only the render function is called (setup is skipped)
- Props are passed to the render function
- The
setupprop is excluded from props - Queued tasks execute after rendering
Component Removal
handle.signalis aborted- Event listeners registered via
handle.on()are cleaned up - Queued tasks execute with an aborted signal
Basic Rendering
The simplest component returns JSX:Rendering with State
Usehandle.update() to trigger re-renders:
Prop Passing
Props flow from parent to child through JSX attributes:Conditional Rendering
Use JavaScript expressions for conditional rendering:Lists and Keys
Use thekey prop to identify list items:
Why Keys Matter
Keys enable efficient diffing and preserve:- DOM nodes - Elements with matching keys are reused, not recreated
- Component state - Component instances persist across reorders
- Focus and selection - Input focus stays with the same element
- Form values - Input values remain with their elements
Key Guidelines
Composition Through Children
Components can compose other components viachildren:
Fragment for Grouping
UseFragment to group elements without adding DOM nodes:
Async Updates
Wait for updates to complete before performing DOM operations:Queued Tasks
Usehandle.queueTask() for work that needs to happen after rendering:
Context for Indirect Composition
Use context to share values without prop drilling:TypedEventTarget for Efficient Updates
For better performance, useTypedEventTarget to avoid updating the entire subtree:
Next Steps
- State Management - Learn state management patterns
- Styling - Style components with the CSS prop
- Events - Handle user interactions