useStoreMap: Simpler method to get a partial object/array
- Dominant language
- TypeScript
- Stars
- 4.9k
- Forks
- 280
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 7
Description
I'd like to just get certain properties on an object. This seems very verbose to accomplish the task:
```ts
const pick = (
obj: T,
keys: readonly K[],
): Pick => keys.reduce((acc, key) => {
acc[key] = obj[key];
return acc;
}, {} as Pick);
```
```ts
const partialState = useStoreMap({
fn: pick,
keys: ['firstKey', 'secondKey'] as const,
store: exampleObjectStore, // Record
});
```
**Is there a simpler, type-safe way to get a partial object?** Something like this would be ideal:
```ts
const partialState = useStoreMap({
keys: ['firstKey', 'secondKey'],
store: exampleObjectStore, // Record
});
```
It would work with arrays in the same way:
```ts
const partialState = useStoreMap({
keys: [1, 3],
store: exampleArrayStore, // T[]
});
```
Contributor guide
Assessment
This issue has not been assessed yet.