gpt4 book ai didi

javascript - 将 DOM 变量作为 props 传递给 Reactjs

转载 作者:行者123 更新时间:2023-11-28 14:56:37 26 4
gpt4 key购买 nike

如果我的问题看起来很荒谬,请原谅我,但我是 ReactJs 的新手。

我有一个反射(reflect)用户登录状态的 react 组件:

<AccountStatus iconsize="medium" activate={[true,false,true]}/>

Image 1

//or using
<AccountStatus iconsize="medium" activate={true}/>

Image 2

我在另一个(非 react )js 文件中单独处理应用程序逻辑,该文件在加载页面时与其他脚本一起加载:

<script src="/assets/js/logic.js" type="text/javascript"></script>

在最后一个文件中,我处理用户身份验证并相应地更新全局变量。我希望能够根据这些全局变量中发生的更改来修改组件的状态。

var user, credential, token;
var providers = {
facebook.com: true,
twitter.com: false,
google.com: true,
};

最佳答案

我认为您应该从不同的方向来满足您的要求。

因此请检查身份验证 here 。这应该是一种相当简单的用户身份验证方法。

In this last file I handle the user authentication and update the global variables accordingly. I'd like to be able to modify the state of the component based on the changes that occur in these global variables.

你的这句话迫使我认为你需要 redux用于全局状态管理。

我知道这将是一件很难让您全神贯注的事情,但这将是正确的方法!

关于javascript - 将 DOM 变量作为 props 传递给 Reactjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42638980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com