useEntities: support multiple list keys

useentities-spread
Alex Gleason 2023-03-10 11:29:31 -06:00
rodzic a0c1bd84c9
commit db06ed42f3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 8 dodań i 3 usunięć

Wyświetl plik

@ -12,8 +12,12 @@ import type { RootState } from 'soapbox/store';
type EntityPath = [
/** Name of the entity type for use in the global cache, eg `'Notification'`. */
entityType: string,
/** Name of a particular index of this entity type. You can use empty-string (`''`) if you don't need separate lists. */
listKey: string,
/**
* Name of a particular index of this entity type.
* Multiple params get combined into one string with a `:` separator.
* You can use empty-string (`''`) if you don't need separate lists.
*/
...listKeys: string[],
]
/** Additional options for the hook. */
@ -39,7 +43,8 @@ function useEntities<TEntity extends Entity>(
const api = useApi();
const dispatch = useAppDispatch();
const [entityType, listKey] = path;
const [entityType, ...listKeys] = path;
const listKey = listKeys.join(':');
const defaultParser = (entity: unknown) => entity as TEntity;
const parseEntity = opts.parser || defaultParser;