Define how to render the component in React. Args: props: The props to render (if None, then use get_props). Returns: The tag to render.
(self, props: dict[str, Any] | None = None)
| 463 | child.apply_theme(theme) |
| 464 | |
| 465 | def _render(self, props: dict[str, Any] | None = None) -> Tag: |
| 466 | """Define how to render the component in React. |
| 467 | |
| 468 | Args: |
| 469 | props: The props to render (if None, then use get_props). |
| 470 | |
| 471 | Returns: |
| 472 | The tag to render. |
| 473 | """ |
| 474 | # Create the base tag. |
| 475 | tag = Tag( |
| 476 | name=self.tag if not self.alias else self.alias, |
| 477 | special_props=self.special_props, |
| 478 | ) |
| 479 | |
| 480 | if props is None: |
| 481 | # Add component props to the tag. |
| 482 | props = { |
| 483 | attr[:-1] if attr.endswith("_") else attr: getattr(self, attr) |
| 484 | for attr in self.get_props() |
| 485 | } |
| 486 | |
| 487 | # Add ref to element if `id` is not None. |
| 488 | ref = self.get_ref() |
| 489 | if ref is not None: |
| 490 | props["ref"] = Var.create(ref, _var_is_local=False) |
| 491 | else: |
| 492 | props = props.copy() |
| 493 | |
| 494 | props.update( |
| 495 | **{ |
| 496 | trigger: handler |
| 497 | for trigger, handler in self.event_triggers.items() |
| 498 | if trigger not in {EventTriggers.ON_MOUNT, EventTriggers.ON_UNMOUNT} |
| 499 | }, |
| 500 | key=self.key, |
| 501 | id=self.id, |
| 502 | class_name=self.class_name, |
| 503 | ) |
| 504 | props.update(self._get_style()) |
| 505 | props.update(self.custom_attrs) |
| 506 | |
| 507 | return tag.add_props(**props) |
| 508 | |
| 509 | @classmethod |
| 510 | @lru_cache(maxsize=None) |