Skip to content

Commit 8ad5793

Browse files
committed
feat: add default type Option<String> for prop class
1 parent a39c58c commit 8ad5793

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ folder. You can preview them at [this site](https://frender-rs.github.io/frender
3434

3535
```toml
3636
[dependencies]
37-
frender = "= 1.0.0-alpha.7"
37+
frender = "= 1.0.0-alpha.8"
3838
```
3939

4040
3. Create `index.html` in the project root directory.
@@ -177,15 +177,28 @@ def_props! {
177177
pub struct MyProps {
178178
// Required prop
179179
name: String,
180+
180181
// Optional prop which defaults to `Default::default()`
181-
age: Option<u8>,
182+
// The following property `age` is optional, and defaults to `None`
183+
age?: Option<u8>,
184+
185+
// The following property `tags` is optional, and defaults to `Vec::default()`
186+
tags?: Vec<String>,
187+
182188
// If the prop type is not specified,
183189
// then frender will infer the type by prop name.
184190
// For example, `class_name` default has type `Option<String>`
191+
// The following property `class_name` is optional, has type Option<String>
185192
class_name?,
193+
194+
// The following property `id` is required, has type Option<String>
195+
id,
196+
186197
// Prop can also have type generics.
187198
// For example, the following is
188-
// the default definition for prop `children`
199+
// the default definition for prop `children`,
200+
// which means it accepts any `Option<TNode>` where TNode implements react::Node,
201+
// and then map the value into `Option<react::Children>` and store it into MyProps.
189202
children<TNode: react::Node>(value: Option<TNode>) -> Option<react::Children> {
190203
value.and_then(react::Node::into_children)
191204
},

crates/frender-macros/src/props_to_tokens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ fn infer_field_type_and_builder(
506506
ty,
507507
}
508508
}
509-
"id" | "class_name" => {
509+
"id" | "class_name" | "class" => {
510510
let ty: syn::TypePath = parse_quote_spanned!(span=>
511511
Option<String>);
512512
let ty = syn::Type::Path(ty);

0 commit comments

Comments
 (0)