# useInvalidateRefdata

## Reference Data Cache Management Hook
A specialized utility for maintaining reference data consistency across the application.
Part of the reference data management ecosystem, designed to work with [`useMutateRefdataCategory`](../useMutateRefdataCategory/README.md) and [`useMutateRefdataValue`](../useMutateRefdataValue/README.md).

## Basic Usage
```jsx
const RefdataUpdater = () => {
  const invalidate = useInvalidateRefdata('license_types');

  const handleUpdate = async () => {
    await updateLicenseTypes();
    invalidate(); // Triggers cache refresh
  };

  return <Button onClick={handleUpdate}>Refresh Data</Button>;
};
```

### 2. Query Key Structure
Uses centralized key generator [`refdataQueryKey`](../../utils/refdataQueryKey/README.md):
```js
refdataQueryKey('media_formats') => ['stripes-kint-components', 'refdata', 'media_formats']
```

## Parameters
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `desc` | string | ✕ | - | Reference data category descriptor |

## Advanced Usage

### Batch Invalidation
```jsx
const invalidateMedia = useInvalidateRefdata('media_types');
const invalidateLicenses = useInvalidateRefdata('license_types');

const handleGlobalRefresh = async () => {
  await Promise.all([
    invalidateMedia(),
    invalidateLicenses()
  ]);
};
```

### Conditional Invalidation
```jsx
const RefdataForm = ({ category }) => {
  const invalidate = useInvalidateRefdata(category?.type);

  const handleSubmit = async (data) => {
    await saveCategory(data);
    if (category) invalidate();
  };
};
```

## Integration Notes

### Performance Considerations
- Prefer targeted invalidations over global refresh
- Combine with mutation hooks for automatic invalidation
- Avoid in tight loops - debounce if needed

### Error Handling
- Safe to call multiple times
- Fails silently if no active queries match
- Returns promise for error chaining:
```js
invalidate().catch(error => logger.error('Refresh failed', error));
```
