Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Q013】有没有使用过 react hooks,它带来了那些便利 #14

Open
shfshanyue opened this issue Nov 6, 2019 · 5 comments
Open
Labels

Comments

@shfshanyue
Copy link
Owner

shfshanyue commented Nov 6, 2019

有没有使用过 react hooks,它有哪些优缺点?

@shfshanyue
Copy link
Owner Author

shfshanyue commented Dec 22, 2019

依我的看法,React hooks 主要解决了状态以及副作用难以复用的场景,除此之外,他对我最大的好处就是在 Console 中不会看到重重叠叠相同名字的组件了(HOC)。

目前使用感觉最爽的两个hook,都是关于请求的。一个是 apollo-clientuseQuery,一个是 swr

@libin1991
Copy link

1.HOC嵌套地狱
2.this
3.逻辑复用
3.tree-shaking

@JeffWong16
Copy link

个人最喜欢的两个点
1, 再也不用操心讨厌的this的问题
2,逻辑复用更加方便,代码逻辑更加清晰

@Muralitob
Copy link

不用去写生命周期了

@yangzi0210
Copy link

1.类组件比起函数组件更难以理解。

2.无需修改组件结构的情况下复用状态逻辑,状态管理更加清晰。

3.不用写类函数就可以使用更多的 React 特性。

4.更符合 React 本身的思想,函数式、组件化。

5.组件树层级变浅 (原本的HOC/render props 等方式增加了组件树层数及渲染,在 React DevTools 中观察过 React 应用,你会发现由 providers,consumers,高阶组件,render props 等其他抽象层组成的组件会形成“嵌套地狱”,这些功能都可以通过强大的自定义的 Hooks 来实现。)

6.不用再去考虑 this 的指向、生命周期问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants