Skip to content

Commit

Permalink
Added a note about ref usage in Oxpecker.Solid
Browse files Browse the repository at this point in the history
  • Loading branch information
Lanayx committed Dec 17, 2024
1 parent 49eb3b1 commit 355c762
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Oxpecker.Solid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ This library doesn't provide support for React-like context. I strongly believe

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` (to be used with [createObj](https://fable.io/docs/javascript/features.html#createobj)).

_Note_: when using `ref(nativeElem)` make sure that `nativeElem` is mutable (e.g. `let mutable nativeElem = Unchecked.defaultof<HTMLDivElement>`).

### Store

Similar to the original implementation in `Fable.Solid` , store has a special helper for updating its fields:
Expand All @@ -88,7 +90,6 @@ setStore // store setter
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:
Expand Down
2 changes: 1 addition & 1 deletion tests/Oxpecker.Solid.Tests/SolidCases/Refs/Refs.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { onMount } from "solid-js";
import { some } from "./fable_modules/fable-library-js.4.23.0/Option.js";

export function Test() {
const htmlCanvas = defaultOf();
let htmlCanvas = defaultOf();
onMount(() => {
console.log(some(htmlCanvas.height + htmlCanvas.width));
});
Expand Down
4 changes: 2 additions & 2 deletions tests/Oxpecker.Solid.Tests/SolidCases/Refs/Refs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ open Fable.Core.JS

[<SolidComponent>]
let Test () =
let htmlCanvas: HTMLCanvasElement = Unchecked.defaultof<_>
let mutable htmlCanvas: HTMLCanvasElement = Unchecked.defaultof<_>
onMount(fun () -> console.log(htmlCanvas.height + htmlCanvas.width))

div().ref(fun _ -> console.log("before mounted")) {
div().ref(fun _ -> console.log("before mounted")) {
canvas(width=256, height=256).ref(htmlCanvas)
}

0 comments on commit 355c762

Please sign in to comment.