liveBook · Manning

Record

As explained in React in Depth

Record is a built-in TypeScript utility type that constructs an object type with a specified set of property keys and a uniform property value type.

Record constructs an object type for maps with a specified key type and uniform value type. It is useful when React state maps user IDs to visibility flags. section 6.1.1

Typed user-visibility state

const [userVisibility, setUserVisibility] = useState<Record<string, boolean>>({}); The type allows an initially empty object while defining string keys and boolean values for later updates. section 6.1.1

const [userVisibility, setUserVisibility] =
  useState<Record<string, boolean>>({});

Inspect the complete useState declaration for a Record-backed object map. section 6.1.1

How React in Depth covers it

How deep it goes
Defines the object-map pattern and demonstrates its use in useState, without exploring advanced key constraints or mapped-type internals.
Examples
Uses a user-visibility map typed as Record<string, boolean> and initialized with an empty object.
What it assumes
Assumes familiarity with TypeScript types, object maps, and React useState.
What you can do after
Apply it via TypeScript and useState to type object maps initialized without entries.
How it connects
Connects TypeScript utility types, object maps, React state, and useState.

Also explained in

Compare how 12 books explain record →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.