【问题标题】:withState vs. withStateHandlerswithState 与 withStateHandlers
【发布时间】:2018-01-24 21:56:06
【问题描述】:

@https://github.com/acdlite/recompose/blob/master/docs/API.md#withstate 的文档对withState 这么说

您可能希望将此状态更新程序与 withHandlers() 一起使用 创建特定的更新函数。

然后它有一个单独的函数withStateHandlers(),虽然形式略有不同,但看起来很相似。

在实际使用方面以及为什么要使用一个而不是另一个,它们有何不同?

【问题讨论】:

    标签: reactjs recompose


    【解决方案1】:

    实际上withStateHandlers() 直到最近版本的recompose 才出现。如果可以的话,我建议使用withStateHandlers(),而不是结合withState()withHandlers()

    withState() 下的文档可能需要更新。

    【讨论】:

    • 啊,所以 withState() + withHandlers() 本质上等同于 withStateHandlers() ?
    • 对于基本用法,是的。对于高级用法,withHandlers 允许您通过 withStateHandlers 不支持的函数创建 stateHandlers,而 withStateHandlers 创建一个 React 实例,而 withSate + withHandlers 创建两个。
    猜你喜欢
    • 2018-02-22
    • 2018-12-22
    • 2019-12-18
    • 2018-02-14
    • 2018-04-04
    • 2019-07-10
    • 2019-02-01
    • 2016-03-23
    • 1970-01-01
    相关资源
    最近更新 更多