conditional statements with use state
Unanswered
Broad-snouted Caiman posted this in #help-forum
Broad-snouted CaimanOP
I'm working on a quize app were i have 3 buttons on home page to get the types of questions (art, science, math) and i am using searchParams to track which question type the user clicked on the home page in page 2. Have a js object where questions are stored. I tried if else statements to display question from js object to ui. i want the question state to get data from const data = file
1 Reply
@Broad-snouted Caiman I'm working on a quize app were i have 3 buttons on home page to get the types of questions (art, science, math) and i am using searchParams to track which question type the user clicked on the home page in page 2. Have a js object where questions are stored. I tried if else statements to display question from js object to ui. i want the question state to get data from const data = file
(I'm not sure if I understood your query right)
Its not the best way. First set up a temporary variable, check conditions, then useState. Example:
And if you have only 2 var, you can use this
Its not the best way. First set up a temporary variable, check conditions, then useState. Example:
let temp;
if(params === 1) temp = "idk"
else temp = "idek"
const [var, setVar] = useState(temp)And if you have only 2 var, you can use this
const [var, setVar] = useState(params === "idk" ? 1 : 2)