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
When attempting to set a CustomVar that inherits from rx.Base in State using the built-in setter, a mismatch warning occurs.
A simple example is provided below.
Warning occured but it is initialized properly without issues using a dictionary.
Only when the first time I clicked the button, warning occured.
If this is considered a problematic situation, I am willing to work on a solution.
To Reproduce
Code
from typing import List
import reflex as rx
class Fruit(rx.Base):
name: str
brix: int
edible: bool
class FruitState(rx.State):
fruits: List[Fruit] = [
Fruit(name="banana", brix=1, edible=True),
Fruit(name="apple", brix=2, edible=True)
]
favorite_fruit: Fruit = None
def fruit_button(fruit: Fruit) -> rx.Component:
return rx.button(
fruit.name,
on_click=FruitState.set_favorite_fruit(fruit)
)
def index() -> rx.Component:
return rx.box(
rx.heading(f"Favorite Fruit : {FruitState.favorite_fruit.name}"),
rx.foreach(
FruitState.fruits,
fruit_button
),
)
app = rx.App()
app.add_page(index)
Log
DeprecationWarning: mismatched-type-assignment has been deprecated in version 0.6.5 Tried to assign value {'name': 'apple', 'brix': 2, 'edible': True} of type <class 'dict'> to field FruitState.favorite_fruit of type
typing.Optional. This might lead to unexpected behavior. It will be completely removed in 0.7.0
The text was updated successfully, but these errors were encountered:
Description
When attempting to set a CustomVar that inherits from rx.Base in State using the built-in setter, a mismatch warning occurs.
A simple example is provided below.
Warning occured but it is initialized properly without issues using a dictionary.
Only when the first time I clicked the button, warning occured.
If this is considered a problematic situation, I am willing to work on a solution.
To Reproduce
Code
Log
The text was updated successfully, but these errors were encountered: