UNPKG

@gravity-ui/data-source

Version:
24 lines (23 loc) 985 B
import { useInfiniteQueryData } from '../impl/infinite/hooks'; import { usePlainQueryData } from '../impl/plain/hooks'; import { notReachable } from '../utils/notReachable'; import { useQueryContext } from './useQueryContext'; export var useQueryData = function useQueryData(dataSource, params, options) { var context = useQueryContext(); var type = dataSource.type; var state; // Do not change data source type in the same hook call if (type === 'plain') { // eslint-disable-next-line react-hooks/rules-of-hooks state = usePlainQueryData(context, dataSource, params, options); } else if (type === 'infinite') { // eslint-disable-next-line react-hooks/rules-of-hooks state = useInfiniteQueryData(context, dataSource, params, // TS can't calculate types in this place options); } else { return notReachable(type, "Data Source type must be plain or infinite, got: ".concat(type)); } return state; }; // #sourceMappingURL=useQueryData.js.map