I am working in a project with React Native and TypeScript. I have a TextInput that convert the Peso Argentino into Real Brasileiro, the currency value is fixed, I pretend to use an API later. However, when I put the value={this.state.coinValue}
or onChangeText={coinValue => this.setState({ coinValue })}
it returns me error in the state or props of the typescript. How can I solve this?
My current code:
interface Props {}interface State { coinValue: number;}export class Exchange extends React.Component<Props, State> { constructor(props: Props) { super(props); this.state = { coinValue: 0 }; } currency = () => { const real = 17.47; const v = this.state.coinValue; const result = v * real; alert("$"+result+" Peso Argentino") } render() { return(<View style={styles.container}><KeyboardAvoidingView style={styles.container} behavior={Platform.OS === "ios" ? "padding" : "height"}> <Header /><View style={styles.header}><Text style={styles.coin}>Moeda</Text><View style={styles.card}><Image style={styles.img} source={arFlag} /><Text style={styles.typeOfCoin}>Peso Argentino</Text><Text style={styles.valueOfCoin}>R$17,28</Text><Feather name="rotate-ccw" size={14} color={colors.heading} /></View></View><View style={styles.value}><Text style={styles.insertValue}>Insira o valor</Text><TextInput style={styles.input} placeholder="9000" /> <View style={styles.btn}><Button title="Converter" /></View></View><View style={styles.convertedValue}> {/** <Text style={visible ? styles.unhideValue : styles.hideValue}>{ newValue }</Text>*/}<Text style={[styles.textValue}>R$10M</Text></View></KeyboardAvoidingView></View> ); }}