javascript - 状态未传递给子组件 reactjs
问题描述
我正在尝试将状态作为道具传递给另一个组件。子组件(页面上的一个按钮)没有收到任何道具。我做了一个console.log
打印从父母收到的道具,但我得到一个空对象{}
。我在这里做错了什么?
这是我的代码的摘录:
贷款.js(父)
<ForecloseBtn id={this.state.lead_id} foreclose={this.state.isForeclosed } test="xyz"/>
ForecloseBtn.js(儿童)
import React from 'react';
import { render } from 'react-dom';
class ForecloseBtn extends React.Component {
constructor(props) {
super(props);
console.log(this.props);
this.state = {
lead_id: this.props.id,
isForeclosed: this.props.foreclose,
sample: this.props.test
};
}
render() {
return (
......
)
}
};
const App = () => (
<ForecloseBtn />
);
export default App;
解决方案
推荐阅读
- python - Pytesseract 不适用于低分辨率图像
- reactjs - 使用 JSON Schema Form (Retool) 输入多个文件
- azure-web-app-service - 在 Azure WebApps 中使用 Tomcat 的 SAML
- c# - 如何递归地填充数组
- numpy - 服务器电脑上的 Numpy 慢
- powershell - 使用 ForEach 而不是 pipe 和 % 编写循环
- excel - 协助使用 Excel VBA 从在线 Web 服务解析 XML
- unity3d - 如何在 Blender 2.9 中重新连接电枢
- ubuntu - 无法在 jetson nano 上安装 OpenCV-4.5.0
- java - 如何在spring legacy环境下正常运行junit test?