Code Monkey home page Code Monkey logo

Comments (12)

pengx17 avatar pengx17 commented on June 1, 2024 1

函数组件应为 functional component

from blog.

shanggqm avatar shanggqm commented on June 1, 2024

@pengx17 感谢回复。
之所以用了function component,是参照了React 官网的叫法。https://reactjs.org/docs/hooks-state.html#hooks-and-function-components

from blog.

pengx17 avatar pengx17 commented on June 1, 2024

确实术语React这边是叫function component 👍 。
内容蛮好的,还没消化完。感觉如果可以对照一下源码就好了

from blog.

manooog avatar manooog commented on June 1, 2024

//通过闭包的方式,实现队列在不同函数中的共享。前提是每次用的dispatch函数是同一个
const dispatch = dispatchAction.bind(null, queue);
return [hook.memoizedState, dispatch]

这里是不是还要进行一次赋值 queue.dispatch = dispatch ?

因为我在后面看到有直接用 queue.dispatch 但是没有赋值。

from blog.

shanggqm avatar shanggqm commented on June 1, 2024

//通过闭包的方式,实现队列在不同函数中的共享。前提是每次用的dispatch函数是同一个
const dispatch = dispatchAction.bind(null, queue);
return [hook.memoizedState, dispatch]

这里是不是还要进行一次赋值 queue.dispatch = dispatch ?

因为我在后面看到有直接用 queue.dispatch 但是没有赋值。

是的,源码这块是有的,的确忽略了。
虽然是伪代码,但你说的这句还是应该加上的,感谢反馈

from blog.

shanggqm avatar shanggqm commented on June 1, 2024

确实术语React这边是叫function component 👍 。
内容蛮好的,还没消化完。感觉如果可以对照一下源码就好了

我基本上是把源码里的核心代码摘出来了,这样比较简单易读。
源码加了太多fiber的逻辑,过于晦涩容易让人望而却步

from blog.

Rainsho avatar Rainsho commented on June 1, 2024

值得读一遍以上的好文。

from blog.

ronniegong avatar ronniegong commented on June 1, 2024

好文,理解Hooks看这篇够了

from blog.

yangnianbing avatar yangnianbing commented on June 1, 2024

很棒的文章,配合Dan Abramov的这篇文章一起食用,效果好极了

from blog.

nieyao avatar nieyao commented on June 1, 2024

image
这里岂不是违反了hooks的规则,在条件语句中使用了hooks,导致hooks的顺序错乱?

from blog.

shanggqm avatar shanggqm commented on June 1, 2024

image
这里岂不是违反了hooks的规则,在条件语句中使用了hooks,导致hooks的顺序错乱?

规则只说定义不能在条件语句里定义,并没有说使用有此限制

from blog.

nieyao avatar nieyao commented on June 1, 2024

image
在条件语句中使用可能会使hooks的调用顺序发生改变

from blog.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.