{"record":{"id":"eacb5a7d7443b444","repo":"marmelab/react-admin","slug":"refetch-is-not-available-for-a-listcontext-built-f","errorCode":null,"errorMessage":"refetch is not available for a ListContext built from useList based on local data","messagePattern":"refetch is not available for a ListContext built from useList based on local data","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/list/useList.ts","lineNumber":16,"sourceCode":"import { useCallback, useEffect, useRef, useState } from 'react';\nimport get from 'lodash/get.js';\nimport isEqual from 'lodash/isEqual.js';\n\nimport { removeEmpty } from '../../util';\nimport { Exporter, FilterPayload, RaRecord, SortPayload } from '../../types';\nimport { useResourceContext } from '../../core';\nimport usePaginationState from '../usePaginationState';\nimport useSortState from '../useSortState';\nimport { useRecordSelection } from './useRecordSelection';\nimport { GetDataOptions, ListControllerResult } from './useListController';\nimport { flattenObject } from '../../dataProvider/fetch';\nimport { defaultExporter } from '../../export';\n\nconst refetch = () => {\n    throw new Error(\n        'refetch is not available for a ListContext built from useList based on local data'\n    );\n};\n\n/**\n * Handle filtering, sorting and pagination on local data.\n *\n * Returns the data and callbacks expected by <ListContext>.\n *\n * @example\n * const data = [\n *     { id: 1, name: 'Arnold' },\n *     { id: 2, name: 'Sylvester' },\n *     { id: 3, name: 'Jean-Claude' },\n * ]\n *\n * const MyComponent = () => {\n *     const listContext = useList({ data });","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/list/useList.ts#L1-L34","documentation":"When a ListContext is created from local data via useList (no dataProvider), there is no server query to re-run, so refetch is intentionally a stub that throws. Calling it on such a context is an API misuse.","triggerScenarios":"Calling listContext.refetch() from useListContext when the list was built with <ListContextProvider value={useList({ data: localArray })}> or <ArrayField>-based contexts.","commonSituations":"Custom list views over local arrays; testing components with mock local data then reusing the same component against context.refetch; adding a refresh button to a local-data list.","solutions":["Don't call refetch on local-data lists; re-render by updating the source data state","Conditionally render a refresh button only when the list is backed by a dataProvider","Switch to a dataProvider-backed List/useListController if server refresh is needed","Use a custom refresh handler that resets your local data instead of refetch"],"exampleFix":"// before\nconst { refetch } = useListContext();\n<Button onClick={() => refetch()} /> // throws on local data\n// after\nconst listContext = useListContext();\n{listContext.data && <Button onClick={() => setLocalData(freshData)} />}\n// or check availability: typeof refetch === 'function'","handlingStrategy":"type-guard","validationCode":"const listContext = useListContext();\nconst canRefetch = typeof listContext.refetch === 'function' && !isLocalDataList;\nif (canRefetch) listContext.refetch();","typeGuard":"const refetchIsAvailable = (ctx: ListControllerResult): ctx is ListControllerResult & { refetch: () => void } =>\n  typeof ctx.refetch === 'function';","tryCatchPattern":"try { refetch(); } catch (e) { if (String(e).includes('local data')) { /* refresh local state instead */ } }","preventionTips":["Only expose refresh buttons for dataProvider-backed lists","Track whether the list uses `data` prop (local) vs dataProvider","Write a component test exercising refetch on your local-data setup"],"tags":["react-admin","local-data","unsupported-api"],"backgroundTag":"api-not-supported-for-local-data","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}