javascript

  • An effect that sets state it also depends on

    An effect listing a value in its dependencies and setting that value in its body is an infinite loop, and the analyser that suggested adding the dependency is…

  • Logical assignment: ||=, &&= and ??=

    The three logical assignment operators short-circuit, which means the right-hand side is not evaluated and the assignment does not happen at all when the operator does not fire.…

  • A composable that registers its own onUnmounted

    Cleanup belongs beside the thing it cleans up, and a composable can register lifecycle hooks because it runs inside the component’s setup scope. A mixin could register hooks…

  • A snapshot test is a diff you agreed to review

    A snapshot test asserts that output has not changed, which is only useful if somebody reads the diff when it does. The regeneration reflex is what makes snapshot…

  • Event delegation moved to the root in 17

    React 16 attached every handler to document and 17 attaches them to the root container, which changes what stopPropagation can prevent. The change exists to make two React…

  • The new JSX transform, and the React import you can delete

    JSX compiled to React.createElement required React to be in scope; the new transform imports what it needs itself. The output is marginally smaller and the ceremony disappears, and…

  • ref survives destructuring and reactive does not

    reactive is a Proxy over an object and reactivity lives in the property access, so pulling a property out of it produces a plain value. The rule that…

  • provide/inject is not a store and should not become one

    Provide and inject pass a value down a component tree without prop drilling, and they hide the dependency from everything that reads the component in isolation. The string…

  • replaceAll, and the regex with /g you no longer need

    String.replace with a string pattern replaces the first occurrence only, which is the most surprised anybody has been by a standard library method. Escaping user input to build…

  • Numeric separators make a constant readable

    An underscore in a numeric literal is ignored by the parser and exists solely so a person can see how many zeros there are. The mistake this prevents…