tezvyn:

Vue, Angular & Svelte

Vue 3, Nuxt, Angular, Svelte, SvelteKit

307 bites

More in Vue, Angular & Svelte — page 14

Vue, Angular & Svelte2 min read

Vue Computed Properties: Derived Values for Cleaner Templates

A Vue computed property is a reactive 'formula' that derives its value from other data. Use it to move complex logic out of your templates, keeping them clean and readable.

Vue, Angular & Svelte2 min read

ref() vs. reactive(): Vue's Two Flavors of Reactivity

ref() is a box for any value (primitive or object) that you must access with .value. reactive() is a proxy for objects only, which you access directly. Use ref() for single values, reactive() for grouping data. The footgun: reactive() fails on primitives.

Svelte's Reactive Assignments with `$: `
Vue, Angular & Svelte2 min read

Svelte's Reactive Assignments with `$: `

Think of Svelte's `$: ` as a magic label that automatically re-runs code when its inputs change. It's used to create derived values, like `$: sum = a + b`. The footgun: the compiler only tracks direct dependencies, not those hidden inside function calls.

Svelte Lifecycle: Mount, Destroy, and Tick
Vue, Angular & Svelte2 min read

Svelte Lifecycle: Mount, Destroy, and Tick

Svelte 5 simplifies the component lifecycle to just two events: creation (`onMount`) and destruction (`onDestroy`). Use `onMount` for DOM setup and return a cleanup function from it. The cleanup only works if the main callback is synchronous, not async.

Angular Component Lifecycle Hooks
Vue, Angular & Svelte2 min read

Angular Component Lifecycle Hooks

Angular's lifecycle hooks are callbacks for a component's life events: creation, updates, and destruction. Use ngOnInit for one-time setup after inputs are ready, and ngOnChanges to react to input changes. The footgun: don't use the constructor for setup.

Vue, Angular & Svelte2 min read

Vue Lifecycle Hooks: Running Code at the Right Time

Vue lifecycle hooks are your cues to run code at specific moments in a component's life. Use `onMounted` to fetch data or `onUnmounted` to clean up timers. The main footgun is that hooks must be registered synchronously during setup, not in an async callback.

Svelte's `{@html}` and `{@debug}`: When to Use Them
Vue, Angular & Svelte2 min read

Svelte's `{@html}` and `{@debug}`: When to Use Them

Svelte's `{@html}` and `{@debug}` offer powerful but risky escapes. `{@html}` renders raw HTML strings, while `{@debug}` acts like a `debugger` statement in your markup. Use them for trusted content and dev-time inspection.

Vue, Angular & Svelte2 min read

Vue Dynamic Components: Swap Components on the Fly

Use Vue's `<component :is="...">` element to render different components based on a state variable, like swapping views in a tabbed interface. The footgun: components are destroyed on switch; use `<KeepAlive>` to preserve their state and avoid losing user…

Vue, Angular & Svelte2 min read

Vue Template Refs: Reaching Past the Virtual DOM

Vue template refs give you a direct handle to a DOM element, bypassing the declarative model. This is for tasks like programmatically focusing an input or initializing a 3rd-party library. The main footgun: the ref is `null` until the component has mounted.

*ngFor trackBy: Smarter DOM Updates in Angular
Vue, Angular & Svelte2 min read

*ngFor trackBy: Smarter DOM Updates in Angular

*ngFor's `trackBy` tells Angular how to uniquely identify items in a list. This prevents it from destroying and recreating the entire list in the DOM on every data update, instead allowing it to reuse existing elements.

Vue, Angular & Svelte2 min read

Vue List Rendering: Why `key` is Not Optional

Think of `key` as a license plate for each item in a list. Without it, Vue just repaints items in order. With `key`, Vue tracks and preserves each item's state across re-renders. This is vital for dynamic lists with stateful components, like form inputs.

Angular Two-Way Binding: [(ngModel)]
Vue, Angular & Svelte2 min read

Angular Two-Way Binding: [(ngModel)]

Think of [(ngModel)] as a walkie-talkie for data, syncing a component property with a template view. It's used in forms where user input immediately updates a variable, and vice-versa. The footgun is overusing it, which creates tangled data flows.

Vue, Angular & Svelte2 min read

Vue's v-model: Two-Way Binding Made Simple

v-model creates a two-way binding that synchronizes form inputs with your JavaScript data. Use it on any form element like an input or textarea. The footgun: it ignores initial HTML attributes; your JavaScript state is always the single source of truth.

Angular Structural Directives: Shape Your DOM
Vue, Angular & Svelte2 min read

Angular Structural Directives: Shape Your DOM

Structural directives shape your DOM by adding, removing, or manipulating HTML elements. Use *ngIf to show/hide a block or *ngFor to loop over a list. The footgun is forgetting the asterisk (*), which is critical syntactic sugar for a more complex template.

Vue, Angular & Svelte2 min read

Vue's v-if vs. v-show: When to Use Which

v-if adds or removes elements from the DOM; v-show just hides them with CSS. Use v-if for conditions that rarely change (like admin access) and v-show for frequent toggles (like a dropdown menu), as it has a lower toggle cost.

Angular: Dynamic Component Loading
Vue, Angular & Svelte2 min read

Angular: Dynamic Component Loading

Programmatically create and render components anywhere in your app, not just where you've hardcoded them. Use it for dynamic dashboards or modal dialogs. The footgun is forgetting to manually destroy components, which leads to memory leaks.

Angular View Encapsulation: Walling Off Your Component Styles
Vue, Angular & Svelte2 min read

Angular View Encapsulation: Walling Off Your Component Styles

View Encapsulation walls off a component's CSS to prevent styles from leaking in or out. By default, Angular emulates a Shadow DOM to scope styles, but you can change this. The footgun is using `None` to fix a style, creating global CSS conflicts.

Svelte Slot Props: Child Informs, Parent Renders
Vue, Angular & Svelte2 min read

Svelte Slot Props: Child Informs, Parent Renders

Svelte slot props let a child component pass data up to its parent's slot. This is key for reusable list components where the child provides data for each item, but the parent controls the rendering. The footgun: the `let:` directive goes on the component tag.

Svelte Context API: Avoid Prop-Drilling
Vue, Angular & Svelte2 min read

Svelte Context API: Avoid Prop-Drilling

Svelte's Context API lets a parent component provide data to any descendant, avoiding 'prop-drilling'. It's ideal for sharing app-wide state like user info or themes. The key footgun: calling `getContext` without a parent `setContext` will throw an error.

Vue, Angular & Svelte2 min read

Vue Provide/Inject: Skip Prop Drilling

Vue's provide/inject lets an ancestor component share data directly with any descendant, avoiding the tedious 'prop drilling' chain. Use it for app-wide data like user info or theme settings. The footgun: providing a simple value is not reactive by default.