Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hobofan/reacty_yew

Generate Yew components from React components via Typescript type definitions
https://github.com/hobofan/reacty_yew

jsx proc-macro react typescript yew

Last synced: 25 days ago
JSON representation

Generate Yew components from React components via Typescript type definitions

Awesome Lists containing this project

README

        

## reacty_yew - Generate Yew components from React component via Typescript type definitions

This is a proof of concept for automatically generating [Yew](https://yew.rs/) components from React components that have Typescript type definitions. Many parts are missing and this **likely shouldn't be used in production!**

[Announcement blog post with a bit more information](https://www.hobofan.com/blog/2020-11-10-reacty_yew/)

## Showcase

For the full example see [./examples/bad_button](./examples/bad_button).

Given a React component:

```tsx
import * as React from "react";

interface BadButtonProps {
color?: string,
text: string,
}

const BadButton = (props: BadButtonProps): JSX.Element => {
return (
window.alert("Click!")}
>
{props.text}

);

};

export { BadButton };
```

An invocation of the `react_component_mod!` macro (takes as input the name of the module to generate, path to the type declarations and the JS global (UMD) that holds the React components) generates a module:

```rust
react_component_mod!(
bad_button;
types = "../js_package/dist/index.d.ts",
global = "BadButtonLib"
);
```

You can directly use the generated component `BadButton` in a Yew component:

```rust
use yew::prelude::*;
use crate::bad_button::BadButton;

// ...
fn view(&self) -> Html {
html! {




}
}
// ...
```