So now there's one last nugget of information that we should cover about props, and that's a utility that EdgeJS comes with called SerializeExcept and SerializeOnly. These utilities allow us to set and serialize props as direct attributes on elements.
Let's take a closer look at how they work.
Attribute Serialization
Within our app layout, let's say we have our main content wrapped in a <main>
element, and we want to transfer all the props to this element's attributes, except for the "title" prop. Thanks to these utilities, we can easily achieve this by…
Inside the component's template, use double curly braces to access the
$props
object.Then, use the
$props.serializeExcept(['title'])
directive to specify which prop to exclude from serialization, in this case, "title."
Join The Discussion! (2 Comments)
Please sign in or sign up for free to join in on the dicussion.
grace-charles
For v6, looks like
serializeOnly
andserializeExcept
have been replaced withonly
andexcept
plustoAttrs
. Details here: https://edgejs.dev/docs/components/propsPlease sign in or sign up for free to reply
tomgobich
Yeah, I need to add a way to tag these series to specific versions! Though the process is still the same, the syntax for this series is using EdgeJS & AdonisJS 5. If you're curious, you can find the full list of differences between EdgeJS 5 vs 6 here:
https://edgejs.dev/docs/changelog/upgrading-to-v6
Please sign in or sign up for free to reply