Ok SO trying to think of the simplest way to ask this first of all the code isn't the most beautiful its the 3rd thing I've ever made in react which I started a week ago and coding maybe a little over 2 months ago. I am making a form that takes in data for COVID simple firstName, lastName, email, and a risklevel The risk level is determined by the count of questions answered yes aka true with if else statements. The count works fine it logs the proper number based off of questions answered true the form information works the only thing it wont do is take my risklevel state and apply it based off of three conditions
function ModalPopUp() {
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
const [FirstName, setFirstName] = useState('');
const [LastName, setLastName] = useState('');
const [email, setEmail] = useState('');
const [riskLevel, setRiskLevel] = useState(0);
const [dryCough, setDryCough] = useState(null);
const [sob, setSob] = useState(null);
const [Aches, setAches] = useState(null);
const [soreThroat, setSoreThroat] = useState(null);
const [headache, setHeadache] = useState(null);
const [fatigue, setFatigue] = useState(null);
const [exposure, setExposure] = useState(null);
// const [age, setAge] = useState(0)
// const [count, setCount] = useState(0)
// const [patients, SetPatients] = useState([]);
const riskState = () => {
let count = 0;
if(dryCough === true) {
count++
}
if(sob === true) {
count++
}
if(Aches === true) {
count++
}
if(soreThroat === true) {
count++
}
if(headache === true) {
count++
}
if(fatigue === true) {
count++
}
if(exposure === true) {
count++
}
if (count <= 2) {
setRiskLevel({riskLevel: riskLevel + 1})
}
if (count > 2 && count <= 4) {
setRiskLevel({riskLevel: riskLevel + 2})
}
if (count > 4) {
setRiskLevel({riskLevel: riskLevel + 3})
}
console.log(dryCough);
console.log(count);
console.log(riskLevel)
}
Aucun commentaire:
Enregistrer un commentaire