Skip to content

Commit

Permalink
remove dataclass from example until they work
Browse files Browse the repository at this point in the history
  • Loading branch information
Lendemor committed Dec 16, 2024
1 parent 393cd64 commit f5700ef
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions docs/vars/custom_vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ Once defined, we can use it as a state var, and reference it from within a compo

```python demo exec
import googletrans
import dataclasses

@dataclasses.dataclass
class Translation:
class Translation(rx.Base):
original_text: str
translated_text: str

Expand All @@ -31,13 +29,12 @@ class TranslationState(rx.State):

@rx.event
def translate(self):
text = googletrans.Translator().translate(self.input_text, dest="en").text
self.current_translation = Translation(original_text=self.input_text, translated_text=text)

self.current_translation.original_text = self.input_text
self.current_translation.translated_text = googletrans.Translator().translate(self.input_text, dest="en").text

def translation_example():
return rx.vstack(
rx.input(on_blur=TranslationState.set_input_text, default_value=TranslationState.input_text, placeholder="Text to translate..."),
rx.input(on_blur=TranslationState.setvar("input_text"), default_value=TranslationState.input_text, placeholder="Text to translate...",),
rx.button("Translate", on_click=TranslationState.translate),
rx.text(TranslationState.current_translation.translated_text),
)
Expand Down

0 comments on commit f5700ef

Please sign in to comment.