Code Monkey home page Code Monkey logo

Comments (5)

lukechu10 avatar lukechu10 commented on May 12, 2024 2

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.

russellwmy avatar russellwmy commented on May 12, 2024 1

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.

emi2k01 avatar emi2k01 commented on May 12, 2024

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 enumerated.

from sycamore.

adamthrash avatar adamthrash commented on May 12, 2024

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.

lukechu10 avatar lukechu10 commented on May 12, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.