Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 02a3af8

Browse files
committed
update v4 spec about sharing props
1 parent f645418 commit 02a3af8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

cli/JSXV4.md

+33
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,36 @@ let p: A.props<_> = {x: "x", y: "y"}
373373
<A x="X" {...p}>
374374
<A {...p} {...p1}>
375375
```
376+
377+
### Shared props type (new feature)
378+
379+
V4 introduces support to set a props type from the outside. It allows sharing of the props type between components.
380+
381+
```rescript
382+
type sharedProps<'a> = {x: 'a, y: string}
383+
384+
module A = {
385+
@react.component(:sharedProps<'a>)
386+
let make = (~x, ~y) => React.string(x ++ y)
387+
}
388+
389+
module B = {
390+
@react.component(:sharedProps<'a>)
391+
let make = (~x, ~y) => React.string(x ++ y)
392+
}
393+
394+
// is transformed to
395+
module A = {
396+
type props<'a> = sharedProps<'a>
397+
398+
let make = ({x, y, _}: props<'a>) => React.string(x ++ y)
399+
...
400+
}
401+
402+
module B = {
403+
type props<'a> = sharedProps<'a>
404+
405+
let make = ({x, y, _}: props<'a>) => React.string(x ++ y)
406+
...
407+
}
408+
```

0 commit comments

Comments
 (0)