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

两个毛病 #33

Open
dev-johnny-gh opened this issue Aug 1, 2020 · 1 comment
Open

两个毛病 #33

dev-johnny-gh opened this issue Aug 1, 2020 · 1 comment

Comments

@dev-johnny-gh
Copy link
Contributor

  • 现在RexProvider在useEffect里面去开始订阅变更,但是RexProvider又在最外层,所以它的useEffect最晚触发,所以在渲染时,子组件对store的更新,都会丢失。除非在子组件里使用setTimeout进行延时,等RexProvider的useEffect生效,但这个比较挫。

  • 第二,更新时,没有callback,例如this.setState,会有一个callback,来通知这个更新已经完成,可以做下一步。现在调用store.update(),没有一个callback可以知道rex已经渲染完成。

@dev-johnny-gh
Copy link
Contributor Author

dev-johnny-gh commented Aug 1, 2020

  • 对于第一个问题,比较复杂,我还没想清楚。

  • 第二个问题可能可以用useState解决

const RexProvider = (props) => {
  const [store, setStore] = useState();

  useEffect(() => {
      props.callback(store);
  }, [store]);
}

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