From ee3b0e614c9ffbfe4bd420ce7253190c94a48bd8 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Mon, 23 Sep 2024 12:40:14 -0700 Subject: [PATCH] fix set value logix for client state (#3966) --- reflex/experimental/client_state.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/reflex/experimental/client_state.py b/reflex/experimental/client_state.py index 9601ca58b8..438ca0a23a 100644 --- a/reflex/experimental/client_state.py +++ b/reflex/experimental/client_state.py @@ -3,6 +3,7 @@ from __future__ import annotations import dataclasses +import re import sys from typing import Any, Callable, Union @@ -174,15 +175,15 @@ def set_value(self, value: Any = NoValue) -> Var: else self._setter_name ) if value is not NoValue: - import re - # This is a hack to make it work like an EventSpec taking an arg value_str = str(LiteralVar.create(value)) - # remove patterns of ["*"] from the value_str using regex - arg = re.sub(r"\[\".*\"\]", "", value_str) - - setter = f"({arg}) => {setter}({str(value)})" + if value_str.startswith("_"): + # remove patterns of ["*"] from the value_str using regex + arg = re.sub(r"\[\".*\"\]", "", value_str) + setter = f"(({arg}) => {setter}({value_str}))" + else: + setter = f"(() => {setter}({value_str}))" return Var( _js_expr=setter, _var_data=VarData(imports=_refs_import if self._global_ref else {}),