Skip to content

使用Hooks构建【函数式组件】,编译不通过 #2909

@JohnPion-Zhang

Description

@JohnPion-Zhang

问题描述
使用Hooks构建函数式组件,编译不通过

复现步骤
[复现问题的步骤]

// 以下是代码,并无其他依赖
import { useState, useEffect } from 'react'
import { View } from '@tarojs/components'
import {
  Dispatch,
  SetStateAction,
  FunctionComponent
} from 'react'

const Example: () => JSX.Element = () => {
  const handleSetCount: (previousCount: number) => number = previousCount  => {
    return previousCount +  1
  }
  const [ count, setCount ]: [ number, Dispatch<SetStateAction<number>> ] = useState(0)
  return <View onClick={() => setCount(handleSetCount) }>{{ count }}</View>
}

export default Example as FunctionComponent<{}>

期望行为
希望函数式组件能通过编译,能支持Hooks特性更好

报错信息

image

系统信息

Taro v1.2 及以上版本已添加 taro info 命令,方便大家查看系统及依赖信息,运行该命令后将结果贴下面即可。

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions