# Manipulating jsoo react attributes as a first class value

**URL:** <https://discuss.ocaml.org/t/manipulating-jsoo-react-attributes-as-a-first-class-value/11657>\
**Category:** Learning\
**Created:** [March 13, 2023, 5:36pm UTC](https://discuss.ocaml.org/t/manipulating-jsoo-react-attributes-as-a-first-class-value/11657 "2023-03-13T17:36:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeroexcuses](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zeroexcuses/32/1692_2.png) [@zeroexcuses](https://discuss.ocaml.org/u/zeroexcuses)\
**Post date:** [March 13, 2023, 5:36pm UTC](https://discuss.ocaml.org/t/manipulating-jsoo-react-attributes-as-a-first-class-value/11657/1 "2023-03-13T17:36:27Z")

</div>

Consider the following code:

```auto
let x = div [| width="..." ; onClick = (fun ... ) |] [...]

```

let us call the width/onClick in the `[| ... |]` the attributes.

Questions:

1. What is the type of this thing? It confuses me we can have width be a string, onClick be a function.

2. Is there a way to manipulate this as a first class value? For example. I want to say:

```auto
let x = [| width = "100"; onClick = ... |] in
let y = take x, but update width with "200"

```

Thanks!

---

<div class="post-metadata">

**Author:** ![zbaylin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zbaylin/32/4047_2.png) [@zbaylin](https://discuss.ocaml.org/u/zbaylin)\
**Post date:** [March 13, 2023, 6:53pm UTC](https://discuss.ocaml.org/t/manipulating-jsoo-react-attributes-as-a-first-class-value/11657/2 "2023-03-13T18:53:08Z")

</div>

Assuming you’re using OCaml syntax here, I think your example is wrong. Those “attributes” as you call them are functions which are called, meaning your example should look like:

```auto
let x = div [| width "npx"; onClick (fun _ -> ()); ... |] [...]

```

These functions (such as [`width`](https://github.com/ml-in-barcelona/jsoo-react/blob/0b54a379bb034321a43de2d6a8773ae0212d5814/lib/dom_html.mli#L139) and [`onClick`](https://github.com/ml-in-barcelona/jsoo-react/blob/0b54a379bb034321a43de2d6a8773ae0212d5814/lib/dom_html.mli#L156)) both return a value of `Dom_html.Prop.t`.

As for your second question, AFAIK there’s no super ergonomic way to do this. One possibility (which I’m unsure about) is that browsers might make some choice about which attribute to use when there are duplicates (i.e. the first/last). You could copy the array `x` and add one extra element which you want to override.

---

<div class="post-metadata">

**Author:** ![zeroexcuses](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/zeroexcuses/32/1692_2.png) [@zeroexcuses](https://discuss.ocaml.org/u/zeroexcuses)\
**Post date:** [March 13, 2023, 7:06pm UTC](https://discuss.ocaml.org/t/manipulating-jsoo-react-attributes-as-a-first-class-value/11657/3 "2023-03-13T19:06:04Z")

</div>

> [@zbaylin](#):
>
> Assuming you’re using OCaml syntax here, I think your example is wrong. Those “attributes” as you call them are functions which are called, meaning your example should look like:

You’re right, I made a mistake, there are no ‘=’. Those are function calls. This actually clears up quite a bit. Thanks!
