Skip to content

Commit f657933

Browse files
committed
add example for module functions
1 parent 150f7b7 commit f657933

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

pages/docs/manual/latest/module-functions.mdx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,37 @@ description: "Module Functions in ReScript"
44
canonical: "/docs/manual/latest/module-functions"
55
---
66

7-
# Module Functions
7+
# Module Functions
8+
9+
```rescript
10+
// next.res - bindings for Next
11+
module type Params = {
12+
type t
13+
}
14+
15+
module MakeNavigation = (Params: Params) => {
16+
@module("next/navigation")
17+
external useNavigation: unit => Params.t = "useNavigation"
18+
}
19+
20+
// Your React component
21+
// component.res
22+
module Params = {
23+
type t = {
24+
tag: string,
25+
item: string,
26+
}
27+
}
28+
29+
module Navigation = Next.MakeNavigation(Params)
30+
31+
@react.component
32+
let make = () => {
33+
let params = Navigation.useNavigation()
34+
<div>
35+
<p> {React.string("Tag: " ++ params.tag)} </p>
36+
<p> {React.string("Item: " ++ params.item)} </p>
37+
</div>
38+
}
39+
```
40+
import { comma } from "postcss/lib/list"

0 commit comments

Comments
 (0)