const HiContainer => (props) {
render{
return(
<h1>Hi {this.props.greet}</h1>
)
}
}
ReactDOM.render(
<HiContainer greet="hi"/>
document.getElementById('root')
);
这段代码有什么问题?调试起来很困难,我看不到控制台中哪行有问题。
另外什么时候需要使用构造函数
?
最佳答案
您有一些语法错误,应该是
const HiContainer = (props) => {
return(
<h1>Hi {props.greet}</h1>
)
}
可以简化为:
const HiContainer = props => <h1>Hi {props.greet}</h1>
你可能需要从基础开始学习,这是箭头函数: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
关于javascript - 无法渲染简单的 react 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41689981/