1
0

generic_component.rs 465 B

1234567891011121314151617181920212223242526
  1. use std::fmt::Display;
  2. use dioxus::prelude::*;
  3. fn main() {
  4. dioxus_desktop::launch(app);
  5. }
  6. fn app(cx: Scope) -> Element {
  7. cx.render(rsx! { generic_child {
  8. data: 0i32
  9. } })
  10. }
  11. #[derive(PartialEq, Props)]
  12. struct GenericChildProps<T: Display + PartialEq> {
  13. data: T,
  14. }
  15. fn generic_child<T: Display + PartialEq>(cx: Scope<GenericChildProps<T>>) -> Element {
  16. let data = &cx.props.data;
  17. cx.render(rsx! { div {
  18. "{data}"
  19. } })
  20. }