【发布时间】:2020-08-27 13:41:32
【问题描述】:
将我的类组件转换为函数组件的方法是什么? 在我的示例中,我尝试显示搜索栏,我需要使用函数组件而不是类组件。
import React, { useState} from 'react';
import { StyleSheet, View } from 'react-native';
import { Table, Row, Rows } from 'react-native-table-component';
const ExampleOne = (props) =>{
const [tableHead, settableHead] = useState(['Head', 'Head2', 'Head3', 'Head4'])
const [tableData,settableData] = useState([
['1', '2', '3', '4'],
['a', 'b', 'c', 'd'],
['1', '2', '3', '456\n789'],
['a', 'b', 'c', 'd']
])
return (
<View style={styles.container}>
<Table borderStyle={{borderWidth: 2, borderColor: '#c8e1ff'}}>
<Row data={tableHead} style={styles.head} textStyle={styles.text}/>
<Rows data={tableData} textStyle={styles.text}/>
</Table>
</View>
)
export default ExampleOne
const styles = StyleSheet.create({
container: { flex: 1, padding: 16, paddingTop: 30, backgroundColor: '#fff' },
head: { height: 40, backgroundColor: '#f1f8ff' },
text: { margin: 6 }
});
【问题讨论】:
-
您能更具体地说明您想了解的内容吗?您是在寻找一般指导方针还是只是为您做这项工作的人?
标签: javascript reactjs react-native react-hooks