【发布时间】:2019-10-30 19:57:23
【问题描述】:
我正在尝试将一个反应组件传递给 ApolloProvider 以供使用。我正在使用打字稿,因此需要正确声明类型等。
我的想法是做以下事情
import { ApolloClient } from 'apollo-client';
import { Component } from 'react';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider } from 'react-apollo';
class ProjectRequest{
public provideApolloToComponent(PassedComponent: Component) {
const client = new ApolloClient({
link: new HttpLink(),
cache: new InMemoryCache(),
});
return (<ApolloProvider client={client}>
<PassedComponent />
</ApolloProvider>);
}
但是我得到以下错误:
对于阿波罗提供者
Generic type 'ApolloProvider<TCache>' requires 1 type argument(s)
对于传递组件
Operator '<' cannot be applied to types 'boolean' and 'RegExp'.ts(2365)
'PassedComponent' refers to a value, but is being used as a type here.
最后是 ApolloProvider jsx 元素
Operator '<' cannot be applied to types 'boolean' and 'RegExp'.ts(2365)
Unterminated regular expression literal.
我认为当 PassedComponent 被修复时,它会被修复。
【问题讨论】:
标签: typescript react-apollo apollo-client