mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-17 09:59:10 +00:00
chore: move src/common/utils to @roleypoly/misc-utils
This commit is contained in:
parent
a374030438
commit
65a8760e86
36 changed files with 38 additions and 465 deletions
11
packages/misc-utils/withContext/contextTestHelpers.tsx
Normal file
11
packages/misc-utils/withContext/contextTestHelpers.tsx
Normal file
|
@ -0,0 +1,11 @@
|
|||
import * as React from 'react';
|
||||
|
||||
export type ContextShimProps<T> = {
|
||||
context: React.Context<T>;
|
||||
children: (data: T) => any;
|
||||
};
|
||||
|
||||
export function ContextShim<T>(props: ContextShimProps<T>) {
|
||||
const context = React.useContext(props.context);
|
||||
return <>{props.children(context)}</>;
|
||||
}
|
2
packages/misc-utils/withContext/index.ts
Normal file
2
packages/misc-utils/withContext/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * as testHelpers from './contextTestHelpers';
|
||||
export * from './withContext';
|
10
packages/misc-utils/withContext/withContext.tsx
Normal file
10
packages/misc-utils/withContext/withContext.tsx
Normal file
|
@ -0,0 +1,10 @@
|
|||
import * as React from 'react';
|
||||
|
||||
export const withContext = <T, K extends T>(
|
||||
Context: React.Context<T>,
|
||||
Component: React.ComponentType<K>
|
||||
): React.FunctionComponent<K> => (props) => (
|
||||
<Context.Consumer>
|
||||
{(context) => <Component {...props} {...context} />}
|
||||
</Context.Consumer>
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue