是否可以通过编程方式将prop添加到现有的React Component。
示例:
if (componentModel.LifestyleType == LifestyleType.Undefined)
componentModel.LifestyleType = LifestyleType.Transient;
我可以这样做吗?
// GenericComp
class GenericComp extends Component {
render = () => <Fragment>{this.props.content ? this.props.content : null}</Fragment>
}
export { GenericComp }
// AnotherFile
import { GenericComp }
// Is that possible to pass content without creating a new class like the // below :
class NewComp extends Component {
render = () => <GenericComp content={myContent} />
}
答案 0 :(得分:0)
我不确定我是否正确理解了您的问题,这是什么意思compose(GenericContent, myProps)
你想要完成的是什么?
主要应用
import React, { Component } from 'react';
import GenericComp from './GenericComp';
const myProps = { text: 'ABCDEF' }
class Main extends Component {
render = () => <GenericComp content={myProps} />
}
export default Main
<强> GenericCop.js 强>
import React, { Component } from 'react';
class GenericComp extends Component {
render = () => <div> {this.props.content ? this.props.content.text : null}</div>
}
export default GenericComp