forked from rescript-association/genType
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hooks.res
113 lines (88 loc) · 3.01 KB
/
Hooks.res
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
@@warning("-3")
type vehicle = {name: string}
@react.component
let make = (~vehicle) => {
let (count, setCount) = React.useState(() => 0)
<div>
<p>
{React.string(
"Hooks example " ++ (vehicle.name ++ (" clicked " ++ (string_of_int(count) ++ " times"))),
)}
</p>
<button onClick={_ => setCount(_ => count + 1)}> {React.string("Click me")} </button>
<ImportHooks person={name: "Mary", age: 71} renderMe={x => React.string(x["randomString"])}>
{React.string("child1")} {React.string("child2")}
</ImportHooks>
<ImportHookDefault
person={name: "DefaultImport", age: 42} renderMe={x => React.string(x["randomString"])}>
{React.string("child1")} {React.string("child2")}
</ImportHookDefault>
</div>
}
export default = make
@react.component
export anotherComponent = (~vehicle, ~callback: unit => unit) => {
callback()
<div> {React.string("Another Hook " ++ vehicle.name)} </div>
}
module Inner = {
@react.component
export make = (~vehicle) => <div> {React.string("Another Hook " ++ vehicle.name)} </div>
@react.component
export anotherComponent = (~vehicle) =>
<div> {React.string("Another Hook " ++ vehicle.name)} </div>
module Inner2 = {
@react.component
export make = (~vehicle) => <div> {React.string("Another Hook " ++ vehicle.name)} </div>
@react.component
export anotherComponent = (~vehicle) =>
<div> {React.string("Another Hook " ++ vehicle.name)} </div>
}
}
module NoProps = {
@react.component
export make = () => <div> ReasonReact.null </div>
}
type cb = (~_to: vehicle) => unit
export functionWithRenamedArgs = (~_to, ~_Type, ~cb: cb) => {
cb(~_to)
_to.name ++ _Type.name
}
@react.component
export componentWithRenamedArgs = (~_to, ~_Type, ~cb: cb) => {
cb(~_to)
React.string(_to.name ++ _Type.name)
}
@react.component
export makeWithRef = (~vehicle) => {
let _ = 34
ref =>
switch ref->Js.Nullable.toOption {
| Some(ref) => <button ref={ReactDOMRe.Ref.domRef(ref)}> {React.string(vehicle.name)} </button>
| None => React.null
}
}
export testForwardRef = React.forwardRef(makeWithRef)
type r = {x: string}
@react.component
export input = React.forwardRef((~r, (), ref) =>
<div ref={Obj.magic(ref)}> {React.string(r.x)} </div>
)
export type callback<'input, 'output> = React.callback<'input, 'output>
export type testReactContext = React.Context.t<int>
export type testReactRef = React.Ref.t<int>
export type testDomRef = ReactDOMRe.domRef
@react.component
export polymorphicComponent = (~p as (x, _)) => React.string(x.name)
@react.component
export functionReturningReactElement = (~name) => React.string(name)
module RenderPropRequiresConversion = {
@react.component
export make = (~renderVehicle: {"vehicle": vehicle, "number": int} => React.element) => {
let car = {name: "Car"}
renderVehicle({"vehicle": car, "number": 42})
}
}
@react.component
export aComponentWithChildren = (~vehicle, ~children) =>
<div> {React.string("Another Hook " ++ vehicle.name)} <div> children </div> </div>