diff --git a/CHANGES.md b/CHANGES.md index bdfbc432e..eb5cf76fc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ # 0.17.0 +* Support custom `data-*` attributes in DOM JSX, including optional string values (@anmonteiro in https://github.com/reasonml/reason-react/pull/933) * Upgrade `ppxlib` lower bound to `0.36` (@anmonteiro in https://github.com/reasonml/reason-react/pull/883) * Remove `fomat` from ReactDOM's props (@davesnx in https://github.com/reasonml/reason-react/pull/929) * Fix typo on `onEncrypted` (@davesnx in https://github.com/reasonml/reason-react/pull/930) diff --git a/docs/adding-data-props.md b/docs/adding-data-props.md index da0fc8fcb..f96ac4132 100644 --- a/docs/adding-data-props.md +++ b/docs/adding-data-props.md @@ -2,21 +2,79 @@ title: Adding data-* attributes --- -Reason doesn't support using props with dashes right now, ie: `data-id` or `data-whatever`. You can overcome this by creating a `Spread` component: +DOM JSX accepts custom data attributes as camelCase props: ```reason -/* Spread.re */ -[@react.component] -let make = (~props, ~children) => React.cloneElement(children, props); +let element =
; ``` -Using Spread: +The rendered element has `data-test-id="item-42"` and `data-state="ready"`. +This works on both HTML and SVG elements. + +## Values + +Data attribute values have type `string`. They can be literals or expressions: + +```reason +let itemId = 42; +let element = ; +``` + +Pass an `option(string)` with `=?` to make an attribute optional. `Some(value)` +sets the attribute, and `None` omits it: ```reason -[@react.component] -let make = () => -