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

使用生命周期替代 useEffect #10

Open
yisar opened this issue Jul 10, 2019 · 0 comments
Open

使用生命周期替代 useEffect #10

yisar opened this issue Jul 10, 2019 · 0 comments

Comments

@yisar
Copy link
Owner

yisar commented Jul 10, 2019

由于 fre 的 useEffect 是发生在 dom 操作后,而小程序是没有 dom 操作的
从语意上讲,也不适合使用 effect 关键词

但是 fard 的每一个节点都是一个 fard 组件,小程序的组件是有生命周期的,它可以用来替代 useEffect

小程序自定义组件的生命周期主要有两个方法

lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    }
  }

在 fard 中,通过 props 进行传递:

const attach = ()=> console.log('load...')
<Header onAttach={attach} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant