我不知道我是否使用了正确的术语,但这就是我要尝试的方法。我正在从我的API之一中获取一些标头详细信息,其中包括不记名令牌和其他详细信息。这些值将被大多数其他反应组件使用。有没有一种方法可以全局存储它而无需使用Redux或将数据传递给所有单个组件?
下面是一个代码片段,该片段从React组件的位置状态获取值。我需要在不使用redux的情况下全局存储这些值。
if (response.httpStatus === 200) {
setIsLoggedIn(true);
//setIsAdmin(response.user.isAdmin!);
setEmailAddress(inputEmailAddress);
history.push('/console',{
token:response.token,
companyID: response.user.companyID,
firstName: response.user.firstName,
lastName: response.user.lastName,
emailAddress: response.user.emailAddress
} //<--- I also need to store this object globally in the browsers scope so that they can be used by all other react components.
);
}
我的问题听起来很愚蠢,可能缺少正确的术语。我的工作主要在API和数据库中。我没有太多使用反应的专业知识或知识。
抱歉我没有在使用Ionic框架。我使用存储电容器来全局存储值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句