[英]Why is the two kinds of code appear different behavior in react-native?
I write this two kinds of code, the first one it appear correct render, but the second is appear incorrect empty content render, I don't know why? 我编写了这两种代码,第一个代码显示正确的渲染,但是第二个代码显示不正确的空内容渲染,我不知道为什么? Is there any one can explain the behavior? 有没有人可以解释这种行为?
import React from 'react'
import { Text } from 'react-native'
const Header = () => {
return <Text style={style.header}>{content}</Text>;
}
const style = {
header: {
fontSize: 20
}
}
const content = "content"
export { Header };
import React from 'react'
import { Text } from 'react-native'
const Header = () => {
return <Text style={style.header}>{content}</Text>;
}
const style = {
header: {
fontSize: 20
}
}
const content = () => {
return "content"
}
export { Header };
In the second case you're defining content
as a function. 在第二种情况下,您将content
定义为函数。 You should call it: 您应该称呼它为:
return <Text style={style.header}>{content()}</Text>;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.