frender
Functional Rendering: React
in Rust
frender is still in alpha and it's api might change.
For now it is recommended to specify the exact version in Cargo.toml
.
Before updating, please see the full changelog in case there are breaking changes.
There are some example apps in
examples
folder. You can preview them at this site.
Quick Start
-
Create a new cargo project
-
Add
frender
to dependencies inCargo.toml
.[] = "= 1.0.0-alpha.8"
-
Create
index.html
in the project root directory.My frender App
-
Modify
src/main.rs
use *;
-
Run with
trunk
Install trunk and then execute:
Then you can navigate to
http://localhost:8080
to see your frender app.
rsx
syntax
rsx
element
use *;
rsx!
Any component name starting with lower case letter [a-z]
will be interpreted as an intrinsic component.
For example, rsx!( <div id="my-div" /> )
will be resolved to:
use *;
use *;
rsx!
rsx
prop
In order to make rsx less verbose, frender provides
IntoPropValue
trait. The value
in
<MyComponent prop={value} />
will be mapped to
IntoPropValue::into_prop_value(value)
.
With this, assuming the prop accepts Option<i32>
,
you can simplify prop={Some(1)}
to prop={1}
,
because T
implements IntoPropValue<Option<T>>
.
If you want to pass the value as is, you can
use :=
to set prop. prop:={value}
Write a component
Component with no props
use *;
// Or you can specify the return type explicitly
Component with props
First, define MyProps
use *;
def_props!
}
Then write the component with the above props:
use *;
Due to the generics, in some very rare cases, you may meet errors like
type annotations needed
cannot infer type for type parameter
.
You can solve it by specifying the type
with the turbofish syntax ::<>
.
For example:
rsx!
rsx!
Hooks
React hooks are also available in frender
.
You checkout the examples for the usage.
Future Development Plans
- Documentation
- Intrinsic svg components
- Export
frender
components to js - Server Side Rendering
- Type checking for
CssProperties
- Css-in-rust (For example, integrate with
emotion/react
)
Contributing
frender
is open sourced at GitHub.
Pull requests and issues are welcomed.
You can also sponsor me and I would be very grateful :heart: