typescript - JSX 元素类型“查询”不是 JSX 元素的构造函数
问题描述
卡住了这个打字稿错误。尝试使用Query
来自react-apollo
.
JSX element type 'Query<any, { id: number; }>' is not a constructor function for JSX elements.
Property 'setState' is missing in type 'Query<any, { id: number; }>'.
[ts] JSX element class does not support attributes because it does not have a 'props' property.
[ts] Property 'query' does not exist on type '{}'
版本:
typescript: "^2.9.2",
apollo-boost: "^0.1.16",
react-apollo: "^2.1.11",
零件:
import gql from "graphql-tag";
import * as React from "react";
import { Query } from "react-apollo";
const ORGANISATION_QUERY = gql`
query OrganisationQuery($id: Long!) {
organisation(id: $id) {
tasksEnabled
}}`;
export class FeatureCardGraphQlComponent extends React.Component<{}
{}> {
public render() {
return (
<Query query={ORGANISATION_QUERY} variables={{ id: 1 }}>
{({ data }) => {
return <div>{data}</div>;
}}
</Query>
);
}}
解决方案
{} 后面好像少了一个逗号
尝试这个:
const ORGANISATION_QUERY = gql`
query OrganisationQuery($id: Long!) {
organisation(id: $id) {
tasksEnabled
}}`;
export class FeatureCardGraphQlComponent extends React.Component<{}, {}> {
public render() {
return (
<Query query={ORGANISATION_QUERY} variables={{ id: 1 }}>
{({ data }) => {
return <div>{data}</div>;
}}
</Query>
);
}}
推荐阅读
- c++ - 如何在 C++ 中进行张量转置
- python - 当我们将 opencv 与 django 一起使用时,请求是如何处理的
- three.js - 三 JS:透视相机中的轴测投影(等轴测视图、二轴测视图和三轴测视图)
- grpc-web - 安装 protoc-gen-grpc-web
- python - 尽我所能理解这一点: AttributeError: 'NoneType' object has no attribute 'text'
- javascript - Express 将 URL 中的“%2F”替换为“/”
- arrays - 有没有办法传递(索引)在 SwiftUI 的 ForEach 中按下了哪个按钮?
- python - Python 如何使用 (4,500) 标记 numpy 形状
- python - “anaconda 提示”和“IPython 控制台”有什么区别?
- typescript - 为什么以下方法不给出语法错误?