使用 ES6,可以将 React 组件表示为函数。
所以,下面的组件
class MyComponent extends React.Component {
render() {
<div>Hi</div>
}
}
也可以这样表示
const MyComponent = (props) => (
<div>Hi</div>
)
我的问题是函数表示是否也允许静态属性。所以,我想知道是否有可能以某种方式将以下组件也表示为一个函数:
class MyComponentWithStaticProperty extends React.Component {
static myProperty = {'hello': 'world'}
render() {
<div>Hi</div>
}
}
最佳答案
const MyComponent = (props) => (
<div>Hi</div>
)
MyComponent.myProperty = {'hello': 'world'};
关于javascript - 是否可以在 React 组件的功能表示中包含静态属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43111817/