Skip to content
\n

Hexagon Component

\n
#[derive(Properties, PartialEq)]\npub struct Props {\n    pub size: usize,\n    pub units: Units,\n    pub text: &'static str,\n}\n\npub struct Hexagon;\n\nimpl Component for Hexagon {\n    type Message = ();\n    type Properties = Props;\n\n    fn create(_: &yew::Context<Self>) -> Self {\n        Self\n    }\n\n    fn view(&self, context: &yew::Context<Self>) -> Html {\n        html! {\n            <div class={classes!(\n                self.styles(),\n            )}>\n                <div class={classes!(\n                    \"hexagon\"\n                )}>\n                    {context.props().text}\n                </div>\n            </div>\n        }\n    }\n}
\n

I don't know if this is the correct way to do this.

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Cloning is the perfectly valid way to pass props down. You want want to make sure the Units type is reference counted so it the data itself isn't cloned every time. The same recommendations about props apply here as well: AttrValue instead of String, etc

","upvoteCount":1,"url":"https://github.com/yewstack/yew/discussions/3744#discussioncomment-10858077"}}}
Discussion options

You must be logged in to vote

Cloning is the perfectly valid way to pass props down. You want want to make sure the Units type is reference counted so it the data itself isn't cloned every time. The same recommendations about props apply here as well: AttrValue instead of String, etc

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Android789515
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants