javascript - 如何设置页面加载反应
问题描述
我正在尝试在页面加载时将某些内容记录到我的控制台以做出反应。我从来没有真正使用过 react 并且我之前只做过 node.js,所以这对我来说是新的。
到目前为止我有这个,但它似乎没有工作。似乎更多的js然后反应。
window.onload(console.log("logging this here"))
我该怎么做?
页面上的更多代码:
class NormalLoginForm extends React.Component {
state = {
error: null,
}
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (err) return
const email = this.props.form.getFieldValue('email')
const password = this.props.form.getFieldValue('password')
var accountStatus1 = ""
AuthorizationHome.doSignInWithEmailAndPassword(email, password)
.then(() => {
firebase.auth().onAuthStateChanged((user) => {
// window.onload(function (console.log("hello"))
解决方案
对于类组件,您可以使用;
ComponentDidMount(){
console.log("logging this here")
}
对于您可以使用的功能组件;
useEffect(() => {
console.log("logging this here")
}, [])
推荐阅读
- .net - 我们能否在 .NET Core 3 中使用 Lamar 解决使用其他接口实现的接口实现?
- mysql - 如何在 mysql 中删除而不删除主要和外部约束
- algorithm - 转换循环以进行并行化
- r - 如何测试\是否在字符串中?
- java - 如何在 Spring Cloud Gateway 中添加特定于路由的自定义过滤器
- reactjs - antd 表通过 react-csv 导出到 csv 使表变慢
- excel - 将存在的文件与 Excel 工作表进行比较
- visual-studio - 只有在工具支持的情况下,我如何有条件地构建 .Net Core 3.0?
- swift - 获取 Anyhashable 类型的数据?
- sql - 将库存图正确连接到公司