{"record":{"id":"2d52701c66901e10","repo":"reflex-dev/reflex","slug":"for-conditional-vars-the-second-argument-must-be","errorCode":null,"errorMessage":"For conditional vars, the second argument must be set.","messagePattern":"For conditional vars, the second argument must be set\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-core/src/reflex_components_core/core/cond.py","lineNumber":204,"sourceCode":"    # Convert the condition to a Var.\n    cond_var = LiteralVar.create(condition)\n    if cond_var is None:\n        msg = \"The condition must be set.\"\n        raise ValueError(msg)\n\n    # If the first component is a component, create a Cond component.\n    if isinstance(c1, BaseComponent):\n        if not isinstance(c2, types.Unset) and not isinstance(c2, BaseComponent):\n            return Cond.create(cond_var.bool(), c1, Fragment.create(c2))\n        return Cond.create(cond_var.bool(), c1, c2)\n\n    # Otherwise, create a conditional Var.\n    # Check that the second argument is valid.\n    if isinstance(c2, BaseComponent):\n        return Cond.create(cond_var.bool(), Fragment.create(c1), c2)\n    if isinstance(c2, types.Unset):\n        msg = \"For conditional vars, the second argument must be set.\"\n        raise ValueError(msg)\n\n    # convert the truth and false cond parts into vars so the _var_data can be obtained.\n    c1_var = Var.create(c1)\n    c2_var = Var.create(c2)\n\n    if c1_var is cond_var or c1_var.equals(cond_var):\n        c1_var = c1_var.to(types.value_inside_optional(c1_var._var_type))\n\n    # Create the conditional var.\n    return ternary_operation(\n        cond_var.bool(),\n        c1_var,\n        c2_var,\n    )\n\n\n@overload\ndef color_mode_cond(light: Component, dark: Component | None = None) -> Component: ...  # pyright: ignore [reportOverlappingOverload]","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-core/src/reflex_components_core/core/cond.py#L186-L222","documentation":"When `rx.cond(condition, c1, c2)` is used with non-component return values (i.e. building a conditional Var rather than a Cond component), the second argument c2 is mandatory because a ternary Var needs both branches. Only component rendering allows an unset c2.","triggerScenarios":"`rx.cond(State.flag, 'yes')` with no third argument, where c1 is a string/Var rather than a component.","commonSituations":"Using rx.cond to produce dynamic text or values and forgetting the else branch; assuming the else defaults to empty string.","solutions":["Supply the second branch: rx.cond(State.flag, 'yes', 'no')","Use rx.cond(State.flag, rx.text('yes')) if you truly want component-only rendering (unset else renders nothing)","Use an empty-string default explicitly: rx.cond(flag, 'yes', '')"],"exampleFix":"// before\nrx.text(rx.cond(State.is_pro, 'Pro'))\n// after\nrx.text(rx.cond(State.is_pro, 'Pro', 'Free'))","handlingStrategy":"validation","validationCode":"val = rx.cond(flag, 'yes', 'no' if not isinstance(c2_given, str) else c2_given)\n# simply: always pass the third argument for value-returning conds","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always give both branches when rx.cond returns text/values","Use rx.match with a default for multi-branch value selection"],"tags":["reflex","conditional-rendering","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}