Hi. I have a problem, I’m using react navigation and I have a formula in which I need to pass a parameter to my const through a textInput automatically.
My operation, I need calculate the area from a circunference and validate if the result is impar or par:
const [valid, setValid] = React.useState('');
const [invalid, setInvalid] = React.useState('');
const [text, setText] = React.useState('');
const pi = 3.1415;
const total = (value) => {
const result = (pi * (value / (2 * pi))*(value / (2 * pi)) ).toFixed(2);
const numint = (pi * (value / (2 * pi))*(value / (2 * pi)) ).toFixed(0);
const rest = numint % 2;
var validation;
const invalido = " ✘ ";
const valido = " ✔ ";
if(rest == 0){
validation = valido;
setInvalid('');
setValid(validation);
}else{
validation = invalido;
setInvalid(validation);
setValid('');
}
setText(result);
};
export default class Calculus extends React.Component {
render(){
return(
<ScrollView style={styles.container}>
<LinearGradient style={styles.background} />
<View>
<Text style={{alignSelf:"center", color: "green"}}>{valid}<Text style={{color: "red"}}>{invalid}</Text></Text>
<TextInput placeholder=" Area" keyboardType="numeric" onChangeText = {total} />
</View>
</Scrollview>
}
I need to pass the “total” parameter to the formula, I tried to put that formula in a function and pass it to it but it didn’t work, and show “invalid” or “valid” parameters; I don’t understand how to do it. This only works in a function but I need this in my class react.component.
Thanks