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

为什么useEnv中的setEnv要在useEffect中触发? #31

Closed
peterczg opened this issue Jul 21, 2022 · 7 comments
Closed

为什么useEnv中的setEnv要在useEffect中触发? #31

peterczg opened this issue Jul 21, 2022 · 7 comments
Labels
feature new feature question Further information is requested taro-hooks-next next version own

Comments

@peterczg
Copy link

Question

理论上来说TARO_ENV 在运行的时候就已经确定了环境,但是看useEnv源码的setter却是在useEffect中触发,是否有什么特殊的case要处理,需要这么做?

如果确定是不可变的,那么用useRef来存性能会更好,一些情况下可以少触发一次render。

function useEnv(): ENV {
  return useRef(getEnv()).current
}
@peterczg peterczg added the question Further information is requested label Jul 21, 2022
@innocces
Copy link
Owner

确实是的。下个版本的这种固定信息类的接口会直接产出。可以等待一下下个版本。

@innocces innocces added the feature new feature label Jul 21, 2022
@peterczg
Copy link
Author

那改的东西不少,我看很多hooks里面都依赖了useEnv

@innocces
Copy link
Owner

因为之前跨端都是用env来判断的. 下个版本会走file的模式. xxx.${env}.ts. 这样会减少大部分的env使用

@peterczg
Copy link
Author

这里要注意⚠️一个问题,就是支持扩展的编译平台,Taro已经支持的几种平台可以走xxx.${env}.ts条件编译,但是第三方自己fork的编译平台,建议留个xxx.ts作为兜底,还是拿getEnv()的值。举个不恰当的例子,比如说鸿蒙,Taro还没发布正式版,就可以走兜底的逻辑,让用户可以正常使用,不至于报错。

@innocces
Copy link
Owner

=。- 只要是不带平台后缀的最后都会兜底会xx.ts. 不过这次更新要限制taro.version >= 330

@innocces
Copy link
Owner

进群来讨论吧

@innocces
Copy link
Owner

innocces commented Sep 2, 2022

新版本已经发布. 暂未宣发. 可以开始尝鲜了 传送门

@innocces innocces closed this as completed Sep 2, 2022
@innocces innocces added the taro-hooks-next next version own label Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new feature question Further information is requested taro-hooks-next next version own
Projects
None yet
Development

No branches or pull requests

2 participants