Skip to content

没考虑用hook重写吗?替换class api #985

Answered by pointhalo
gitHber asked this question in Q&A
Discussion options

You must be logged in to vote

先说下结论:【不计划】
再说下我们的看法:
hooks与class各有好处,不存在谁比谁一定更优这种说法,不应该脱离使用场景来评价。

  1. 在写业务组件时,hooks会更便捷一些。
    在写基础UI组件时,因为有很多特定交互逻辑是依赖生命周期函数的,所以传统的class反而更有优势。而且对于复杂组件而言,hooks的形式组织代码,在可阅读性上跟class会有一定差距。

  2. Semi 的组件架构是 foundation / adapter 分层的。foundation 层完全与前端框架无关,可用于适配任意前端技术栈。hooks 仅限 react 体系内,不好支持我们做与框架无关的逻辑抽象。

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by DaiQiangReal
Comment options

You must be logged in to vote
2 replies
@gitHber
Comment options

@pointhalo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
feature request Request new feature
2 participants
Converted from issue

This discussion was converted from issue #984 on July 21, 2022 09:36.