【发布时间】:2019-09-04 17:24:23
【问题描述】:
我在网上看到了一些教程,大部分示例都在使用
一个类组件,例如
export default class App extends Component {
constructor() {
super();
//set state here and data source
}
componentDidMount() {
//get json data here
}
render() {
return(
blah blah blah
)
}
}
如果我想让一个子组件有一个调用 fetch 的功能怎么办?
//NewComponent.js
//this is my sub component
const NewComponent = () => {
return(
<FlatList />
//I want a list of data here
)
}
const getData = () => {
//call fetch here
}
export default NewComponent
那么在我的第二个代码 sn-p 中,如何调用 getData 以便我在 NewComponent 中显示数据?
【问题讨论】:
标签: react-native react-native-android react-native-ios react-native-flatlist