首页 > 解决方案 > 如何设置页面加载反应

问题描述

我正在尝试在页面加载时将某些内容记录到我的控制台以做出反应。我从来没有真正使用过 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"))

标签: javascriptnode.jsreactjs

解决方案


对于类组件,您可以使用;

ComponentDidMount(){
console.log("logging this here")
}

对于您可以使用的功能组件;

useEffect(() => { 
console.log("logging this here")
}, [])

推荐阅读