首页 > 解决方案 > Preact + TypeScript 不允许我直接调用 h 函数而不是使用 JSX

问题描述

请参阅此最小示例代码:

import { FunctionalComponent, h } from 'preact';

const Text: FunctionalComponent = () => {
    const tag = 'div'
    const props = {}
    const children = 'I am children'

    return (
        h(tag, props, children)
    )
}

它说:Cannot invoke an expression whose type lacks a call signature. Type 'typeof h' has no compatible call signatures.

如果我直接使用 JSX 就可以了:

在此处输入图像描述

如何直接使用该h功能?

标签: javascriptreactjstypescriptpreact

解决方案


推荐阅读