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

Render Props

Basic Render Props

[@react.component]
let make = () => {
  <Loader render={() => <div />} />
};
/* Loader.re */

[@react.component]
let make = (~render) => {
 <div> {render()} </div>
};

Children as Render Props

[@react.component]
let make = (~children) => {
  <Loader>
    {person => <div> {React.string(person.name)} </div>}
  </Loader>;
};
/* Loader.re */

[@react.component]
let make = (~children) => {
  let person = {name: "Peter"};
  <div> {children(person)} </div>;
};
← Working with Optional DataImporting JS into Reason →