Topppy / hexo-blog

my hexo new blog
https://topppy.github.io/hexo-blog/
2 stars 0 forks source link

如果传入了参数[],useEffect内的值会锁定初始值 #18

Open Topppy opened 4 years ago

Topppy commented 4 years ago

If you pass an empty array ([]), the props and state as inside the effect will always have their initial values.

useEffect(
  () => {
    const subscription = props.source.subscribe();
    console.log(this.state.a)
    return () => {
      subscription.unsubscribe();
    };
  },
  [],
);

a will never change.