Skip to content

Commit 97ddb3a

Browse files
author
Kevan Stannard
committed
Add obj decorator
1 parent f0bc375 commit 97ddb3a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

misc_docs/syntax/decorator_obj.mdx

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
id: "obj-decorator"
3+
keywords: ["obj", "decorator"]
4+
name: "@obj"
5+
summary: "This is the `@obj` decorator."
6+
category: "decorators"
7+
---
8+
9+
The `@obj` decorator is used to create functions that return JavaScript objects
10+
with properties that match the function's parameter labels.
11+
12+
### Example
13+
14+
<CodeTab labels={["ReScript", "JS Output"]}>
15+
16+
```res
17+
@bs.obj
18+
external action: (~name: string, unit) => _ = ""
19+
20+
let helloAction = action(~name="Hello")
21+
```
22+
23+
```js
24+
function helloAction(param) {
25+
return {
26+
name: "Hello",
27+
}
28+
}
29+
```
30+
31+
</CodeTab>
32+
33+
### References
34+
35+
* [Convert External into JS Object Creation Function](/docs/manual/latest/generate-converters-accessors#convert-external-into-js-object-creation-function)

0 commit comments

Comments
 (0)