Oxpecker.Solid 0.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Oxpecker.Solid --version 0.2.1                
NuGet\Install-Package Oxpecker.Solid -Version 0.2.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oxpecker.Solid" Version="0.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Oxpecker.Solid --version 0.2.1                
#r "nuget: Oxpecker.Solid, 0.2.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Oxpecker.Solid as a Cake Addin
#addin nuget:?package=Oxpecker.Solid&version=0.2.1

// Install Oxpecker.Solid as a Cake Tool
#tool nuget:?package=Oxpecker.Solid&version=0.2.1                

Oxpecker.Solid

Fable (4.23.0+) bindings for the Solid.js and Solid-router.js libraries based on Oxpecker's view engine. This library DOES NOT depend on Fable.Solid package.

Introduction post: https://medium.com/@lanayx/oxpecker-goes-full-stack-45beb1f3da34

Nuget package dotnet add package Oxpecker.Solid

Markup example:

open Oxpecker.Solid // this library namespace
open Browser // Fable browser bindings (needed for console.log)

[<SolidComponent>] // this attribute is required to compile components to JSX that Solid understands
let itemList items = // regular function arguments, no props!
    let x, setX = createSignal 0 // just sample of reactive state usage
    ul() { // ul tag
        For(each = items) { // Solid's built-in For component
            yield fun item index -> // function called for each item
                li() { // li tag
                    span() { index() } // index is reactive getter from Solid
                    span() { item.Name } // string field inside span tag
                    button(onClick=fun _ -> console.log("Removing item...")) { // onClick event handler
                        "Remove" // button text
                    }
                }
        }
    }

Documentation:

You mostly need to refer to the official site for the Solid.js documentation: https://docs.solidjs.com.

You can also check TODO list sample in the repository to get a better understanding of how the code will look like in your application.

There are some details that are specific to Oxpecker's view engine implementation:

SolidComponent attribute

This attribute tells Fable compiler plugin (Oxpecker.Solid.FablePlugin) that this function should be transformed into Solid compatible JSX during build time. It has no effect at runtime. This plugin is referenced by Oxpecker.Solid package and will be automatically added to your project when you install it, no manual reference is needed.

Props

With this library you can forget about props and special helpers created for managing them. You can use regular function arguments instead. You can be as creative as you want with your function arguments, they can be records, functions, ref cells (especially useful for passing refs from child to parent) or any other regular F# types.

Fragment element

Fragment element get transformed in Solid's <>...</>tag. It's used to wrap multiple elements without creating a new DOM element.

For and Index elements

These elements are used to iterate over a list of items (you can read about the difference here). You'll need to use yield keyword before the iterating function because currently F# computation expressions don't allow for implicit yield for functions.

Context

This library doesn't provide support for React-like context. I strongly believe it's an antipattern, and encourage you to use global signals or stores instead.

Special JSX attributes

Note that attr:, on:, bool:, ref attributes are exposed as F# methods in the API: elem.on(...), elem.attr(...) etc. Also, style and class' are attributes when accepting string, while style' and classList are methods when accepting object.

Store

Similar to the original implementation in Fable.Solid , store has a special helper for updating its fields:

setStore // store setter
    .Path // special property to access store fields
    .Map(_.data) // choose which field to update
    .Update(newData) // update field with a new value

Resource

Again, just as in the original implementation in Fable.Solid, resource is a special object, so instead of JS resource() call, you'll need to use resource.current in F#.

Router

Router namespace is Oxpecker.Solid.Router. It contains router related components and functions. To render a router you still need to decorate router function with SolidComponent attribute:

open Oxpecker.Solid.Router

[<SolidComponent>]
let MyRouter () =
    Router() {
        Route(path="/", component'=Home)
        Route(path="/about", component'=About)
    }

render (MyRouter, document.getElementById "root")

Aria

Similar to the original Oxpecker.ViewEngine additional Aria attributes reside in a separate module, so you need to write open Oxpecker.Solid.Aria to access them.

Lazy

For components lazy loading you'll need to use lazy' function together with another importComponent function.

lazy'(fun () -> importComponent("./ComponentA"))

will be translated to

lazy(() => import("./ComponentA"))
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.4.1 73 12/20/2024
0.4.0 108 12/5/2024
0.3.0 112 11/13/2024
0.2.2 93 10/31/2024
0.2.1 93 10/29/2024
0.2.0 104 10/22/2024
0.1.0 90 10/17/2024
0.0.2 109 10/10/2024
0.0.1 101 10/10/2024

Fable output got minimized