Comments (5)
New plan:
I want to eventually get rid of the component
attribute macro and make components just functions that return Template<G>
. This would be more idiomatic in Rust as well as reducing the number of proc-macros.
To make it more ergonomic to pass parameters to components, the template!
macro will be modified to allow the following new syntax:
template! {
Component(prop_1=2) {
prop2=3
}
// or
Component(prop_1=2, prop2=3)
Both syntaxes will mean the same thing.
from sycamore.
Maybe a huge changes, I agree on making sycamore more into a Rust instead of React or Yew. Can we break the template children as individual macro with designed patterns (traits). So it will not increase the complexity of template macro.
from sycamore.
How would this work if I want to have a component that only accepts specific children components? Say I want to force this structure:
Tabs {
Tab(title="Tab 1") {
h1 { "hey" }
}
Tab(title="Tab 2") {
img(src="...")
}
}
Or would it be up to the caller to ensure that only Tab
components are passed to Tabs
?
I'd prefer if we had something like yew
where children of a component are enum
erated.
from sycamore.
Can an example of how to use children in components be added to the documentation? I have the following minimal example (CSS and other parts of the page have been removed):
use sycamore::prelude::*;
#[component]
pub fn Card<'a, G: Html>(cx: Scope<'a>) -> View<G> {
view! { cx,
div() {}
}
}
fn main() {
sycamore::render(|cx| view! { cx,
Card {
p { "Test"}
}
});
}
This code compiles and displays correctly when p {"Test"}
is commented out. However, when I try to include a paragraph within my Card component, I get this error.
error[E0599]: no method named `children` found for struct `UnitBuilder` in the current scope
--> src/main.rs:13:27
|
13 | sycamore::render(|cx| view! { cx,
| ___________________________^
14 | | Card {
15 | | p { "Test"}
16 | | }
17 | | });
| |_____^ method not found in `UnitBuilder`
|
= note: this error originates in the macro `view` (in Nightly builds, run with -Z macro-backtrace for more info)
I've tried changing the Card function to accept Props
, but if that's the solution, I'm not able to figure out how to implement it correctly.
from sycamore.
@adamthrash yeah sorry the docs for 0.8 has some missing parts. I'll try to get to it soon.
from sycamore.
Related Issues (20)
- Can't use `build` as an argument name in `Props` nor `component(inline_props)`
- Console error "closure invoked recursively or destroyed already" when setting signal checked in the conditional. HOT 2
- API docs correction for Functions hydrate_to: "use hydrate_to" should read and link as "use hydrate" HOT 2
- std::option::Option<sycamore::prelude::View<_>> doesn't implement std::fmt::Display HOT 2
- Failed to iterate over a vector from the Keyed iteration. HOT 2
- run instructions for Hello World example fail with sycamore 0.8 HOT 4
- Views do not refresh after signal update on the nested Drag and drop. HOT 1
- view! compile error when passing empty Children through component
- Router fails to navigate if wrapping view is missing
- `on_rendered` hook HOT 1
- `Portal` doesn't update dynamic views inside it
- Ability to execute async code when rendering in SSR mode
- Remove Rc and RefCell from Signal? HOT 3
- Use-after-free with create_effect HOT 9
- Empty false condition for builder `dyn_if`
- Builder pattern `button().on(ev::click...)` fails: undeclared crate or module. HOT 3
- `component(|| MyComponent` seems to serve no purpose. HOT 2
- Builder version `input().bind_value(...)` has requirements that the `view! ` macro doesn't HOT 3
- Documentation recommends deprecated `weealloc` HOT 1
- Example of mutating a collection HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sycamore.