MCPcopy Create free account
hub / github.com/dot-agent/nextpy / _render

Method _render

nextpy/frontend/components/component.py:465–507  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)

Callers 2

renderMethod · 0.95
_renderMethod · 0.45

Calls 9

get_propsMethod · 0.95
get_refMethod · 0.95
_get_styleMethod · 0.95
add_propsMethod · 0.95
TagClass · 0.90
itemsMethod · 0.80
createMethod · 0.45
copyMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected