Files
pezkuwi-apps/packages/react-api/src/hoc/api.tsx
T
Satoshi Qazi Muhammed 45d479d2ec Move to @pezkuwi/dev 0.86.4 (eslint 10 toolchain)
- dev ^0.86.4 at the root and in packages/apps; directives renamed by
  pezkuwi-dev-migrate-eslint10.
- eslint --fix with the 0.86.4 config; one fix broke syntax
  (typescript-eslint prefer-optional-chain turned
  `(isStarted && onStart) && onStart()` into `(isStarted && onStart?.();`
  in TxButton) and is corrected by hand.
- The remaining findings fixed rather than disabled: optional chains
  (each suggestion reviewed), `cause` on rethrown errors, `if` instead of
  `a && promise` in effects, parallel instead of sequential awaits in
  Promise.all, Error rejections, no `delete` on arrays (the storage query
  cache is a Map; an upload's file list no longer keeps a hole), no
  `[object Object]` stringification (TFunction's second argument is text
  or options), dead code removed (referenda's never-shown expand button,
  react-query's unused CoreDescriptor).
2026-10-10 02:06:12 +04:00

38 lines
1.1 KiB
TypeScript

// Copyright 2017-2026 @pezkuwi/react-api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiProps, SubtractProps } from '../types.js';
import type { DefaultProps } from './types.js';
import React from 'react';
import { ApiCtx } from '@pezkuwi/react-hooks/ctx/Api';
import { assert } from '@pezkuwi/util';
export default function withApi <P extends ApiProps> (Inner: React.ComponentType<P>, defaultProps: DefaultProps = {}): React.ComponentType<any> {
class WithApi extends React.PureComponent<SubtractProps<P, ApiProps>> {
private component: any = React.createRef();
public override render (): React.ReactNode {
return (
<ApiCtx.Consumer>
{(apiProps?: ApiProps): React.ReactNode => {
assert(apiProps?.api, 'Application root must be wrapped inside \'react-api/Api\' to provide API context');
return (
<Inner
{...defaultProps}
{...(apiProps as any)}
{...this.props}
ref={this.component}
/>
);
}}
</ApiCtx.Consumer>
);
}
}
return WithApi;
}