You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 15, 2023. It is now read-only.
* update v4 spec about sharing props
* fix the example of shared props for v4 spec
* clean up the spec about shared props
* Update JSXV4.md
* update jsx v4 spec about shared props constraint
Co-authored-by: Cristiano Calcagno <[email protected]>
V4 introduces support to control the definition of the `props` type by passing as argument to `@react.component` the body of the type definition of `props`. The main application is sharing a single type definition across several components. Here are a few examples:
380
+
381
+
382
+
```rescript
383
+
type sharedprops<'x, 'y> = {x: 'x, y: 'y, z:string}
384
+
385
+
module C1 = {
386
+
@react.component(:sharedProps<'a, 'b>)
387
+
let make = (~x, ~y) => React.string(x ++ y ++ z)
388
+
}
389
+
390
+
module C2 = {
391
+
@react.component(:sharedProps<string, 'b>)
392
+
let make = (~x, ~y) => React.string(x ++ y ++ z)
393
+
}
394
+
395
+
module C3 = {
396
+
type myProps = sharedProps<int, int>
397
+
@react.component(:myProps)
398
+
let make = (~x, ~y) => React.int(x + y)
399
+
}
400
+
```
401
+
402
+
The generated code (some details removed) looks like this:
403
+
```rescript
404
+
@@jsxConfig({version: 4, mode: "classic"})
405
+
406
+
type sharedprops<'x, 'y> = {x: 'x, y: 'y, z: string}
407
+
408
+
module C1 = {
409
+
type props<'a, 'b> = sharedProps<'a, 'b>
410
+
let make = ({x, y, _}: props<_>) => React.string(x ++ y ++ z)
411
+
}
412
+
413
+
module C2 = {
414
+
type props<'b> = sharedProps<string, 'b>
415
+
let make = ({x, y, _}: props<_>) => React.string(x ++ y ++ z)
0 commit comments