Skip to content

Version 0.16.0

Compare
Choose a tag to compare
@chasefleming chasefleming released this 28 Nov 00:42
· 137 commits to main since this release

🚀 New Features

elem.None for Conditional Rendering and Empty Elements

None now simplifies cases where conditional rendering requires either an element or no output at all. The function provides a straightforward way to express the absence of an element without compromising the readability or structure of your code.

In conditional rendering, None serves as an ideal placeholder for cases where no output is required. For example, when using None in conjunction with the If function, it allows for cleaner and more expressive code. Consider a scenario where you need to render a welcome message conditionally:

showWelcomeMessage := false
welcomeMessage := elem.Div(nil, elem.Text("Welcome to our website!"))

content := elem.Div(nil, 
    elem.If[elem.Node](showWelcomeMessage, welcomeMessage, elem.None())
)

Here, welcomeMessage is only rendered if showWelcomeMessage is true. Otherwise, None ensures that there is no output.

None also makes it straightforward to create explicitly empty elements like <div></div>, useful in various layout and design contexts:

emptyDiv := elem.Div(nil, elem.None())
// Outputs: <div></div>