You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To delete a property from an object or an item from an array, just set its path to undefined.
// Deletes 'count' from the store$store.setKey('count',undefined)// -> { user: { name: 'Luke', age: 42 }}
Working with Arrays
DeepMap fully supports arrays as the root value or nested within your state. You can use standard array syntax [index] in your paths.
//Beforeconst$store=deepMap<StoreProps[]>([{}])// Type Error//Afterconst$store=deepMap<StoreProps[]>([{}])// OK
TypeScript Support
The package is written in TypeScript and provides autocomplete for all methods and properties.
// Define your type with 'type' keyword instead of 'interface'// for better autocompletetypeUserType={id?: string}const$userT=deepMap<UserType>({})$userT.setKey('id','uuidString')// Suggestion autocomplete
Typescript automatically infers the type of the store value.
typeStoreProps={count?: number}const$store=deepMap<StoreProps>({})$store.setKey('count','randomString')// Type Error -> 'string' is not assignable to 'number'// IMPORTANT: an empty path ('') is treated as the root object$someStore.setKey('','randomString')// Replaces the entire store