The code below is just an example I found online.
import { observable, computed } from "mobx";
import { observer } from "mobx-react";
import React from "react";
import { SafeAreaView, Text, TextInput, StyleSheet } from "react-native";
@observer
class Shop extends React.Component {
@observable price = 9;
@observable quantity = 11;
@computed get total() {
return this.price * this.quantity;
}
render() {
return (
<SafeAreaView style={styles.container}>
<Text>Price: </Text>
<TextInput value={this.price} onChangeText={value => { this.price = value }} />
<Text>Quantity: </Text>
<TextInput value={this.quantity} onChangeText={value => { this.quantity = value }} />
<Text>Total (Price and Quantity): {this.total}</Text>
</SafeAreaView>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
})
Sadly, most of the example about MobX in React Native I found online are used for Class Component.
Could anyone kind convert this code into a functional component?
Thank you