【发布时间】:2021-01-01 15:19:38
【问题描述】:
我有一个 Fire 类,如果用户未连接,uid 返回 undefined,如果用户已连接,则返回字符串(他的 uid)。
有时我的渲染依赖于此。
例如:
const [auth, setAuth] = useState<undefined|string>(Fire.shared.uid);
[...]
<Text>{(auth == undefined) ? "not authentificated" : "great")}</Text>
我们可以想象用户没有连接,所以文本将是not authentificated。
现在他将在另一个页面中登录或注册,因此Fire 类中的 uid 变量将发生变化。
那么我应该如何改变状态值呢?
没有useState global之类的吗?
谢谢。
【问题讨论】:
标签: reactjs react-native components expo state