Patterns 6 patterns
Components
Patterns for building and composing UI components. Most frontend apps today are built out of components, and these patterns are about writing components that are easy to reuse and easy to follow. They include keeping the code that renders the UI separate from the code that fetches the data, and setting things up when a component mounts and cleaning them up again when it unmounts.
- Component Lifecycle Setting things up when a component mounts, and cleaning them up again when it updates or unmounts, prevents memory leaks and stale data.
- Message Thread Storing a conversation as an ordered list of messages, each with a role and its own status, so streaming and errors only affect one turn.
- Presentational vs. Container Presentational components render the UI, and container components manage the data and business logic behind it.
- Prompt Input An auto-growing message composer where Enter sends and Shift+Enter adds a newline, with a send button that becomes a stop button while the model replies.
- Props and Attributes Components get their data and configuration from the outside, through properties or attributes.
- Pure Component Components that render the same output for the same inputs, with no side effects, so memoization works and tests are predictable.