小编Jes*_*sus的帖子

语法错误:未知:默认情况下不支持命名空间标签

尝试将 svg 作为 React 组件下载时出现以下错误。

语法错误:未知:默认情况下不支持命名空间标记。React 的 JSX 不支持命名空间标签。您可以打开“throwIfNamespace”标志来绕过此警告。

import React from "react";
import { ReactComponent as LO } from "../a/Logo.svg"
import { NavLink } from "react-router-dom";

const Logo = () => (
  <>
    <NavLink to={"/"}>
     <LO width={"40px"} height={"40px"} />
    </NavLink>
  </>
);

export default Logo;
Run Code Online (Sandbox Code Playgroud)

是什么原因 ?

svg reactjs

28
推荐指数
5
解决办法
2万
查看次数

没有重载匹配这个调用。重载 1 of 2,

我有store.js文件

import { createStore, combineReducers } from "redux";
import reducerADD from "../reducer/reducerADD"

export const store = createStore(combineReducers({ reducerADD}));
Run Code Online (Sandbox Code Playgroud)

当我更改格式时store.tsx出现错误:

No overload matches this call.
  Overload 1 of 2, '(reducers: ReducersMapObject<{ reducerADD: { lastName: string; firstName: string; password: string; email: string; }[]; }, any>): Reducer<{ reducerADD: { lastName: string; firstName: string; password: string; email: string; }[]; }, AnyAction>', gave the following error.
    Type '(state: never[] | undefined, action: action) => { lastName: string; firstName: string; password: string; …
Run Code Online (Sandbox Code Playgroud)

typescript react-redux

18
推荐指数
2
解决办法
5万
查看次数

“抽象类型 X 必须在运行时解析为具有值的字段 Query.user 的对象类型

这是我的代码

模式

gql`
  type Query {
    user: X!
  }
  type User {
    name: String!
  }
  type Time {
    age: Int!
  }
  union X = User | Time
`;
Run Code Online (Sandbox Code Playgroud)

解析器

{
  X: {
    __resolveType: obj => {
      if (obj.name) return { name: "Amasia" };
      if (obj.age) return { age: 70 };
      return null;
    }
  },
  Query: {
    user: () => {
      return {
        name: "Amasia"
      };
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

要求

query {
user{
  ... on User {
    name
  }
  ... on …
Run Code Online (Sandbox Code Playgroud)

node.js graphql-js apollo-server

17
推荐指数
1
解决办法
5669
查看次数

扩展 Object.setPrototypeOf() 与 Object.create

我知道两种继承函数构造函数的方法。

选项 1 Object.create

function x(x, y) {
  this.x = x;
  this.y = y;
}

x.prototype.XDD = function() {};


function y(c, r) {
  x.call(this, 1, 2);
  this.r = r;
  this.c = c;
}

y.prototype = Object.create(x.prototype);
y.prototype.YDD = function() {};
y.prototype.XDD = function() {};
y.prototype.constructor  = y;

var rect = new y(1, 2);
Run Code Online (Sandbox Code Playgroud)

选项 2 Object.setPrototypeOf()

function x(x, y) {
  this.x = x;
  this.y = y;
}

x.prototype.XDD = function() {};

function y(c, r) {
  x.call(this, 1, 2);
  this.r = …
Run Code Online (Sandbox Code Playgroud)

javascript

6
推荐指数
1
解决办法
1289
查看次数

如何将 cookie 从 apollo-server 传递到 apollo-clenet

突变

Mutation: {
  signUp: (_, { res }) => {
    try {
      res.cookie("jwt", "token", {
        httpOnly: true
      });
      return "Amasia";
    } catch (error) {
      return "error";
    }
  };
}
Run Code Online (Sandbox Code Playgroud)

Apollo-clenet-反应

const [addTodo, { loading, error, data }] = useMutation(gql);

  const [formSignUp, setFormSignUp] = useState({
    lastName: '',
    firstName: '',
    password: '',
    email: '',
  });

  const change = e => {
    const { value, name } = e.target;
    setFormSignUp({ ...formSignUp, [name]: value });
  };
Run Code Online (Sandbox Code Playgroud)

当我从反应中提出请求时。这是我从服务器得到的答案。

1)数据 {"data": {"signUp": "Amasia"}}

2)网络 …

cookies node.js graphql apollo-server react-apollo

5
推荐指数
1
解决办法
3551
查看次数

是否可以使用表单和反应组件创建动态页面

我想使用textarea和react组件来创建一个表单。react组件会写在文本区里面,组件结构会显示在底部。我想把这个字符串保存在数据库中,以便以后检索并以某种方式将其转换为 jsx 页面。基本上,我说的一切都非常相似markdown,但我只想使用反应组件。如果流行的包是为此设计的?

例子

const Prism = ({ language }) => {
  return <div style={{ color: "#45E700" }}>{language}</div>;
};

export default function App() {
  const [text, setText] = useState(`<Prism language={"javascript"}/>`);
  return (
    <div>
      <textarea
        value={text}
        onChange={(e) => {
          setText(e.target.value);
        }}
      />
     <Render src={text} />
    </div>
  );
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

javascript textarea reactjs

5
推荐指数
0
解决办法
53
查看次数

字符串类型的 $lastName 用于期望字符串类型的位置

这可能编码

架构

import { gql } from 'apollo-server-express';

export default gql`
  extend type Mutation {
    signUp(
      lastName: String!
    ): String!
  }
`;
Run Code Online (Sandbox Code Playgroud)

解析器

{
  Query: {},
  Mutation: {
    signUp: async (
      _,
      { lastName}
    ) => {
      try {
        console.log(lastName)
        return 'ok';    
      } catch (error) {
        return 'error';
      }
    },
  },
};
Run Code Online (Sandbox Code Playgroud)

要求

mutation($lastName:String){
  signUp(lastName:$lastName)
}
Run Code Online (Sandbox Code Playgroud)

查询验证

{"lastName":"Darjo" }
Run Code Online (Sandbox Code Playgroud)

我无法理解,但我收到错误

"类型为 \"String\" 的变量 \"$lastName\" 用于期望类型为 \"String!\" 的位置。",

但是当我移除标志时 lastName: String一切正常。

我就是无法理解。是什么原因 ?。

javascript node.js graphql apollo-server

2
推荐指数
1
解决办法
6685
查看次数