Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 返回React节点的TypeScript方法_Reactjs_Typescript - Fatal编程技术网

Reactjs 返回React节点的TypeScript方法

Reactjs 返回React节点的TypeScript方法,reactjs,typescript,Reactjs,Typescript,我正在尝试用TypeScript编写一个方法,该方法返回一个ReactNode: const getNode = (Tag: string, children: string): React.ReactNode => { return <Tag>{children}</Tag>; }; 如何修复此错误?我建议在这种情况下避免使用JSX,直接使用React.createElement(标记,{},子元素)我建议在这种情况下避免使用JSX,直接使用React.

我正在尝试用TypeScript编写一个方法,该方法返回一个
ReactNode

const getNode = (Tag: string, children: string): React.ReactNode => {
    return <Tag>{children}</Tag>;
};

如何修复此错误?

我建议在这种情况下避免使用JSX,直接使用
React.createElement(标记,{},子元素)

我建议在这种情况下避免使用JSX,直接使用
React.createElement(标记,{},子元素)

为什么不使用
React.createElement()
?为什么不使用
React.createElement()
getNode('p', 'Hello World'); // returns <p>Hello World</p>
getNode('h1', 'Title'); // returns <h1>Title</h1>
TS2559: Type { children: string; } has no properties in common with 'IntrinsicAttributes'.