Publish to my blog (weekly)

Using the State Hook – React A Hook is a special function that lets you “hook into” React features. For example, useState is a Hook that lets you add React state to function components. Normally, variables “disappear” when the function exits but state variables are preserved by React. If we wanted to store two different values in state, we would call useState() twice. State variables can hold objects and arrays just fine, so you can still group related data together. However, unlike this.setState in a class, updating a state variable always replaces it instead of merging it. Hooks at a...

Publish to my blog (weekly)

Composables | Vue.js stateful logic involves managing state that changes over time. A simple example would be tracking the current position of the mouse on a page. // by convention, composable function names start with "use"   export function useMouse () { As we can see, the core logic remains identical - all we had to do was move it into an external function and return the state that should be exposed. Just like inside a component, you can use the full range of Composition API functions in composables. The same useMouse() functionality can now be used in any component. Each component instance calling useMouse() will create its own copies of x and y ...