V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
lisisi

可以把 React hook 理解为 @decorator(装饰器) 的作用吗?

  •  
  •   lisisi · Jun 25, 2019 · 6965 views
    This topic created in 2507 days ago, the information mentioned may be changed or developed.
    都在不破坏 /不重写原函数的基础上,实现了新的功能。hook 和 @decorator 原理上有区别吗?
    7 replies    2019-07-26 20:43:21 +08:00
    ech0x
        1
    ech0x  
       Jun 26, 2019 via iPhone
    “ Hooks are functions that let you “ hook into ” React state and lifecycle features from function components. Hooks don ’ t work inside classes — they let you use React without classes. (We don ’ t recommend rewriting your existing components overnight but you can start using Hooks in the new ones if you ’ d like.)”
    我不懂 JavaScript,不过看这个描述应该是不一样的 hook 跟 react 生命周期有关。
    python 的装饰器只是高级函数的语法糖而已。
    jason94
        2
    jason94  
       Jun 26, 2019
    两个完全不一样的东西~~建议补一补基础,先把两者的定义弄明白了。
    byenow
        3
    byenow  
       Jun 26, 2019
    @decorator 是对 Class 的修改,基于 Class Components,React Hooks 基于 Function Components
    bestie
        4
    bestie  
       Jun 27, 2019
    decorator 更类似于高阶函数( HOC )
    azh7138m
        5
    azh7138m  
       Jul 9, 2019
    完全不一样的东西,建议阅读 https://github.com/acdlite/recompose
    decorator 怎么就 hoc 了。。。
    ahonn
        6
    ahonn  
       Jul 21, 2019
    看完这个你就懂了
    kwrush
        7
    kwrush  
       Jul 26, 2019
    @bestie hoc 就是装饰器模式吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1011 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 22:37 · PVG 06:37 · LAX 15:37 · JFK 18:37
    ♥ Do have faith in what you're doing.