I write functional HOC to add query in component. HOC must accept functional and classes components.
I write this code:
const LISTS_QUERY = gql`
query List {
list {
id
address
name
}
}
`;
interface WithListQueryProps {
listQueryResult: QueryResult<ListQuery>;
}
type WithList =
<T extends WithListProps, S extends {}>(Component: React.FC<T> | React.ComponentClass<T, S>)
=> (props: any)
=> JSX.Element;
export const withList: WithList = (Component) => {
return props => (
<Query<ListQuery>
query={LISTS_QUERY}
>
{listQueryResult => (
<Component
{...props}
listQueryResult={listQueryResult}
/>
)}
</Query>
);
};
This HOC called so:
interface Props {
userName: string;
}
export const MenuConnect: React.FC<Props> = (props: Props) => {
const MenuBehaviourWithList = withList(MenuBehaviour);
return (
<MenuBehaviourWithList {...props}/>
);
};
HOC worked. I don't like any.
Need change type props in type WithList in HOC from any to your.
Write type inside function. Swap call to imperative.