lwc-patterns

Implements Lightning Web Component patterns for data binding, events, and Apex integration.

Updated Jul 2, 2026
One-click install
npx skills add https://github.com/padjei/SF_Build --skill lwc-patterns-padjei
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: lwc-patterns
Source: https://github.com/padjei/SF_Build/tree/main/.claude/skills/lwc-patterns
Command: npx skills add https://github.com/padjei/SF_Build --skill lwc-patterns-padjei

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Salesforce developers building Lightning Web Components often struggle with choosing between wire and imperative Apex calls, structuring parent-child communication, and avoiding security pitfalls like XSS via innerHTML. This Skill provides a consolidated reference of proven LWC patterns so components are built correctly the first time. ## Core Features & Use Cases - Component Architecture Guidance: Separates container components (data, wire adapters, Apex) from presentational components (@api props, events) with correct naming conventions. - Data Access Patterns: Shows when to use @wire with reactive properties versus imperative async Apex calls, including error handling templates. - Security & Performance Rules: Covers XSS prevention, event bubbling configuration, lifecycle cleanup in disconnectedCallback, and meta XML target configuration. - Use Case: When building a record page component that loads related contacts and notifies a parent on save, apply the wire pattern with $recordId, dispatch a CustomEvent with detail payload, and render errors with the SLDS alert template. ## Quick Start Ask the AI to build a Lightning Web Component that loads contacts for the current record and handles errors following the lwc-patterns guidelines.

Frequently Asked Questions about lwc-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call Apex from a Lightning Web Component?▼

Import the Apex method and either use @wire with reactive parameters for automatic refresh, or call it imperatively with async/await inside connectedCallback. Wire is preferred; use imperative only when wire does not fit the scenario.

When should I use wire vs imperative Apex in LWC?▼

Use @wire when data should auto-refresh when reactive properties like $recordId change. Use imperative calls for one-time loads in connectedCallback or when you need explicit control over timing and error handling.

How do child LWC components communicate with parents?▼

The child dispatches a CustomEvent with a detail payload, and the parent listens via an on-eventname attribute. Set bubbles: true and composed: false to keep the event within the shadow DOM boundary.

Is innerHTML safe to use in Lightning Web Components?▼

No, innerHTML is an XSS vector and should never be used in LWC. Use lwc:dom="manual" only with fully sanitized strings, and avoid eval() and new Function() entirely.

Which meta XML targets can an LWC be exposed to?▼

An LWC can target lightning__RecordPage, lightning__AppPage, lightning__HomePage, lightning__FlowScreen, and lightning__UtilityBar by declaring them in the component's meta XML targets block.