With the help of answer of this question I need help with the specific syntax on how to retrieve values from option types in the following case.
type Query = {
q : string
pageSize : int option
}
let search (query : Query) =
let url = sprintf "foo.com?q=%spageSize=%i" query.q (query.pageSize |> 10 |< query.pageSize) // ???
Syntax help for (query.pageSize |> 10 |< query.pageSize)
The option tag contains the value that would be used when selected. The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean attribute. The option that is having the 'selected' attribute will be displayed by default on the dropdown list.
The DefaultValue property specifies text or an expression that's automatically entered in a control or field when a new record is created. For example, if you set the DefaultValue property for a text box control to =Now(), the control displays the current date and time.
So, you can set a default value by passing the value of the option in the value prop of the select input element. This is very convenient in a controlled component as you only have to update the value in one place.
Option.defaultValue
is your friend:
type Query = {
q : string
pageSize : int option
}
let q = {q = "foo"; pageSize = None}
let p = q.pageSize |> Option.defaultValue 10
The answer you linked provides a pretty clear illustration of the syntax:
input |> defaultArg <| ""
In your case, the input is query.pageSize
and the default value is 10
instead of empty string. So:
query.pageSize |> defaultArg <| 10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With