You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The "I accept the Expensify Terms of Service" checkbox not checked when retuning from step 2 #20871
Please re-state the problem that we are trying to solve in this issue.
The checkbox values are not retained when returning back to the previous step.
What is the root cause of that problem?
The root cause of this issue is that we're using two props to determine if the checkbox is checked. We're using isChecked and value prop. The value prop is set by the Formhere.
For the case mentioned in this bug, the value is set as true by the Form but the isChecked prop is false. On the first mount, the state value is true initially but after this effect runs, the state value becomes false, thus causing the checkbox to be unchecked.
What changes do you think we should make in order to solve the problem?
The simplest way to fix this is to change defaultProp value of the value to be undefined instead of false. Then in the effect here, we can add the following:
if (props.value !== undefined) return;
What alternative solutions did you explore? (Optional)
We can also remove isChecked prop altogether and just use value everywhere. Likewise, we can also change the Form component, such that for checkboxes, it sets isChecked prop instead of the value prop here.
So our useEffect inside CheckboxWithLabel will look like this:
// we should update the checkbox value when props.value is changed, because our isChecked state isn't re-calculateduseEffect(()=>{setIsChecked(props.isChecked||props.value);},[props.isChecked,props.value]);
What alternative solutions did you explore? (Optional)
Activity
melvin-bot commentedon Jun 15, 2023
Triggered auto assignment to @slafortune (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.melvin-bot commentedon Jun 15, 2023
Bug0 Triage Checklist (Main S/O)
Platformsin OP are ✅)allroundexperts commentedon Jun 15, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
The checkbox values are not retained when returning back to the previous step.
What is the root cause of that problem?
The root cause of this issue is that we're using two props to determine if the checkbox is checked. We're using
isCheckedandvalueprop. Thevalueprop is set by theFormhere.For the case mentioned in this bug, the value is set as
trueby theFormbut theisCheckedprop isfalse. On the first mount, thestatevalue istrueinitially but after this effect runs, the state value becomesfalse, thus causing the checkbox to be unchecked.What changes do you think we should make in order to solve the problem?
The simplest way to fix this is to change
defaultPropvalue of thevalueto beundefinedinstead offalse. Then in the effect here, we can add the following:What alternative solutions did you explore? (Optional)
We can also remove
isCheckedprop altogether and just usevalueeverywhere. Likewise, we can also change theFormcomponent, such that for checkboxes, it setsisCheckedprop instead of thevalueprop here.hungvu193 commentedon Jun 16, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
The "I accept the Expensify Terms of Service" checkbox not checked when retuning from step 2
What is the root cause of that problem?
I agree with Sibtain's proposal about the root cause of this issue is about the code inside
CheckboxWithLabel:App/src/components/CheckboxWithLabel.js
Lines 92 to 94 in bd0e843
What changes do you think we should make in order to solve the problem?
Since
isCheckedis a state, it won't re-calculated when the props.value change, we should do it dynamicallyApp/src/components/CheckboxWithLabel.js
Line 84 in bd0e843
So our
useEffectinsideCheckboxWithLabelwill look like this:What alternative solutions did you explore? (Optional)
N/A
bernhardoj commentedon Jun 17, 2023
It's fixed in this PR #20091
luacmartins commentedon Jun 19, 2023
I agree has already been fixed in my PR. Closing.