ReasonReact

ReasonReact

  • Docs
  • Try
  • Examples
  • Community
  • Blog
  • Languages iconEnglish
    • 日本語
    • Español
    • Français
    • 한국어
    • Português (Brasil)
    • Русский
    • 中文
    • 繁體中文
    • Help Translate
  • GitHub

›Recipes & Snippets

Recipes & Snippets

  • A List of Simple Examples
  • Adding data-* attributes
  • Working with Optional Data
  • Render Props
  • Importing JS into Reason
  • Importing Reason into JS
  • ReasonReact using ReactJS
  • ReactJS using ReasonReact
  • Example Projects
  • GraphQL & Apollo
  • Styling: Tailwind CSS
Edit

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:

/* Spread.re */
[@react.component]
let make = (~props, ~children) => React.cloneElement(children, props);

Using Spread:

[@react.component]
let make = () =>
  <Spread props={"data-cy": name}>
    /* This div will now have the `data-cy` attribute in the DOM! */
    <div />
  </Spread>;
← A List of Simple ExamplesWorking with Optional Data →