javascript - 如何从 React 中的扩展类传递道具?
问题描述
最近我一直在一个项目中工作,我需要尽可能保持代码最干净。这就是为什么我在一个组件中工作的原因,该组件需要从另一个组件扩展一些特性,但我还需要传递一些道具来获得一些行为作为回报。但是有一个问题:我在构造函数中添加了一个道具,但是有一个函数没有接收/似乎没有那个道具:
class SampleClassOne extends PureComponent<Props>{
Constructor(Props){
console.log(props) // In this console.log, the variable aditionalVar appears
super(props){
{
}
functionOne(){
const {
varOne,
varTwo,
varThree,
aditionalVar
} = this.props
console.log(this.props) // In this console.log, the variable aditionalVar does not appear
render(){
...
}
}
}
class SampleClassTwo extends SampleClassOne {
Constructor(Props){
super({...props, aditionalVar: true}) // This is where I'm adding the new variable
}
}
}
我不知道我是否清楚我要问的问题......我如何确保我从其他扩展的组件添加的新变量可以被扩展其类的所有组件接收。
谢谢你的帮助
解决方案
推荐阅读
- android - 如何在Android中将mutableMap添加到拦截器
- javascript - 在服务器端渲染的上下文中,“渲染”是什么意思?
- r - 使用 ggplot2 在堆积条形图上的透明层
- datetime - Netsuite 中的 FTL 日期格式
- maven - 如何在 Maven 中找到工件版本的来源?
- reactjs - 抽屉导航器 React Native 中的条件渲染
- powershell - 将bat文件转换为powershell脚本
- python - 具有多列的 Pandas 数据框条件验证
- javascript - 尝试使用 PHP 和 JS 向自己提交 HTML 表单,但它不起作用
- excel - 是否可以使用创建的函数从另一张表中获取特定数据?