Javascript 当我不接受构造函数上的参数时,如何知道何时向组件发送道具

Javascript 当我不接受构造函数上的参数时,如何知道何时向组件发送道具,javascript,reactjs,Javascript,Reactjs,React如何知道有关道具的信息,我正在向组件发送道具,我不接受构造函数上的参数,而是呈现方法访问道具 import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; import reportWebVitals from './reportWebVitals'; ReactDOM.render( <React.StrictMode> <App myApp={'my

React如何知道有关道具的信息,我正在向组件发送道具,我不接受构造函数上的参数,而是呈现方法访问道具

import ReactDOM from 'react-dom';
import './index.css';

import App from './App';

import reportWebVitals from './reportWebVitals';
ReactDOM.render(
  <React.StrictMode>
    <App myApp={'myApp'}/>
  </React.StrictMode>,
  document.getElementById('root')
);
// this is app component
import React, {Component} from 'react';
class App extends Component {
  constructor() {
    super()
    this.state = {};
    console.log(this.props.myApp) // undefined
  }
  render() {
    console.log(this.props.myApp) // 'myApp' how and why, i'm not accepting arguments in contrutor why and how render method know this.props.myApp
  }
}
exports default App;
// this is my assumption what react doing
const obj = new App(props);

您需要重建构造函数:

constructor(props) {
  super(props);
  console.log(this.props.myApp); // 'myApp'
}
更多信息请点击此处:

我想知道,当我不接受构造函数中的参数时,如何使用呈现方法访问道具。类似的讨论可以在这里找到:调用构造函数后,立即从外部对实例执行React set.props。