My learning diary

useContext, useForm, and useFieldArray

I’m fortunate to have the opportunity to work with react-hook-form again. And work with it better. The following worked well for me: // MultiStepForm.tsx import { createContext, Dispatch, SetStateAction } from 'react' import { SubmitHandler, useFieldArray, UseFieldArrayReturn, useForm, UseFormReturn, } from 'react-hook-form' interface SomeComplexInput { someKey: string someValue: string } interface MultiStepFormInput { formFieldA: string formFieldB: SomeComplexInput[] } interface OtherContext { // Other frontend-specific values e.g. active form step index } export const MultiStepFormContext = createContext( {} as UseFormReturn<MultiStepFormInput> & UseFieldArrayReturn<MultiStepFormInput, 'formFieldB', 'id'> & OtherContext, ) export const MultiStepForm = () => { const form = useForm<MultiStepFormInput>({ mode: 'all', }) // Use fieldArray.

Continue reading "useContext, useForm, and useFieldArray"

for-in and for-of

I needed to change my async code into synchronous. I didn’t need to track the index of the array, so I wanted a for...?? loop. Was it or was it for...of!? Example: for (let key in someObject) const a = [4,5,6] const b = [{'k1':'v1'},{'k2':'v2'},{'k3':'v3'}] const c = {'k1':'v1'} for (let d in a) { console.log(d) } // 0 1 2 for (let d in b) { console.log(d) } // 0 1 2 for (let d in c) { console.

Continue reading "for-in and for-of"

Fixing a11y

I thought I’d need to jump through many hoops to resolve an a11y issue in this site. Today, I realised I didn’t need to. From my previous Lighthouse reports, Heading elements are not in a sequentially-descending order had been a thorn in the flesh. I didn’t want to override the original styles of the headers. But I wanted my h2 to look like h3. I wanted my h3 to look like h5.

Continue reading "Fixing a11y"

The SSH command

This is what man ssh gives: ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It is intended to provide secure encrypted communications between two untrusted hosts over an insecure network. X11 connections, arbitrary TCP ports and UNIX-domain sockets can also be forwarded over the secure channel. A simple usage would be: ssh $USERNAME@$TARGET_HOST And you will be prompted for your password.

Continue reading "The SSH command"