effector / effector/effector

useStoreMap: Simpler method to get a partial object/array

Open
#424 12 comments 0 reactions 0 assignees View on GitHub
question seems outdated
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.