react中字段响应式
class中用法:
import React, { Component } from 'react'
export default class Index extends Component<any, any> {
constructor(props) {
super(props)
this.state = {
settingInfo: {},
}
}
async componentDidMount() {
let settingInfo = await Service.getSettingInfo(this.context, {
page_session_id: 'kUeombnhdm',
})
this.setState({ settingInfo: settingInfo })
}
render() {
return <View style={{ marginTop: 50 }}>{this.state.settingInfo.errorMsg}</View>
}
}
function中用法:
import React, { useEffect, useState } from 'react'
const Index = () => {
const [driver, setDriver] = useState(false)
useEffect(() => {
setDriver(false)
}, [])
return <View className={styles.backgroundIcon}>{driver}</View>
}
export default Index