Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation updates for 0.16 #864

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 0 additions & 113 deletions docs/callback-handlers.md

This file was deleted.

135 changes: 0 additions & 135 deletions docs/children.md

This file was deleted.

10 changes: 3 additions & 7 deletions docs/clone-element.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
title: cloneElement
---

<aside class="warning">
The Record API is in feature-freeze. For the newest features and better support going forward, please consider migrating to the new <a href="https://reasonml.github.io/reason-react/docs/en/components">function components</a>.
</aside>
Signature: `let cloneElement: (React.element, ~props: Js.t({..})=?, 'anyChildrenType) => React.element`

Signature: `let cloneElement: (reactElement, ~props: Js.t({..})=?, 'anyChildrenType) => reactElement`

Same as ReactJS' [cloneElement](https://reactjs.org/docs/react-api.html#cloneelement). However, adding extra props to a ReasonReact component doesn't make sense; you'd use a [**render prop**](https://reactjs.org/docs/render-props.html). Therefore, `ReasonReact.cloneElement` is only used in edge-cases to convert over existing code.
Same as ReactJS' [cloneElement](https://reactjs.org/docs/react-api.html#cloneelement). However, adding extra props to a ReasonReact component doesn't make sense; you'd use a [**render prop**](https://reactjs.org/docs/render-props.html). Therefore, `ReasonReact.cloneElement` is only used in edge-cases.

```reason
let clonedElement =
ReasonReact.cloneElement(
React.cloneElement(
<div className="foo" />,
~props={"payload": 1},
[||]
Expand Down
16 changes: 8 additions & 8 deletions docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let make = (~name) => {
This snippet is doing quite a bit! The first thing you might notice is the decorator attribute above the definition. `[@react.component]` tells ReasonReact that you're writing a component with named args syntax (`~name`), but that you would like to compile it into a function that takes a JS object as props which is how React works. Concretely, this attribute will generate code for you that looks like this:

```reason
[@bs.obj]
[@mel.obj]
external makeProps: (~name: 'name, ~key: string=?, unit) => {. "name": 'name} = "";

let make = (Props) => {
Expand All @@ -39,7 +39,7 @@ let make = (Props) => {
};
```

It has added a new function called `makeProps` which uses [`[@bs.obj]`](https://melange.re/v2.0.0/communicate-with-javascript/#using-jst-objects) to create your props object. This function gets compiled away by Melange and will be replaced by object literals when used.
It has added a new function called `makeProps` which uses [`[@mel.obj]`](https://melange.re/v4.0.0/communicate-with-javascript#using-js-t-objects) to create your props object. This function gets compiled away by Melange and will be replaced by object literals when used.

### A note on `children`

Expand Down Expand Up @@ -113,7 +113,7 @@ Reason also always opts for the safest form of a given hook as well. So `React.u

## Hand-writing components

You don't need to use the `[@react.component]` declaration to write components. Instead you can write a pair of `foo` and `fooProps` functions such that `type fooProps: 'a => props and foo: props => React.element` and these will always work as React components! This works with your own version of [`[@bs.obj]`](https://melange.re/v2.0.0/communicate-with-javascript/#using-jst-objects), [`[bs.deriving abstract]`](https://melange.re/v2.0.0/communicate-with-javascript/#convert-records-into-abstract-types), or any other function that takes named args and returns a single props structure.
You don't need to use the `[@react.component]` declaration to write components. Instead you can write a pair of `foo` and `fooProps` functions such that `type fooProps: 'a => props and foo: props => React.element` and these will always work as React components! This works with your own version of [`[@mel.obj]`](https://melange.re/v4.0.0/communicate-with-javascript#using-js-t-objects), [`[bs.deriving abstract]`](https://melange.re/v4.0.0/communicate-with-javascript#using-external-functions), or any other function that takes named args and returns a single props structure.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may need some kind of way to centrally update the melange version that we talk about.


## Interop

Expand All @@ -122,7 +122,7 @@ You don't need to use the `[@react.component]` declaration to write components.
The make function above is a normal React component, you can use it today with code like:

```js
const MyComponent = require('./path/to/Component.bs.js').make;
const MyComponent = require('./path/to/Component.js').make;

<MyComponent name="Regina" />
```
Expand All @@ -134,21 +134,21 @@ It also works seamlessly with [`[@genType]`](https://github.com/cristianoc/genTy
Using a component written in JS requires a single external to annotate the types it takes.

```reason
[@bs.module "./path/to/Component.js"][@react.component]
[@mel.module "./path/to/Component.js"][@react.component]
external make: (~name: string) => React.element = "default";
```

This `[@react.component]` annotation will, again, generate both `make` and `makeProps` functions for you with the correct types. Here's an example of what this desugars to without `[@react.component]`:

```reason
[@bs.obj]
[@mel.obj]
external makeProps: (~name: 'name, ~key: string=?, unit) => {. "name": 'name} = "";

[@bs.module "./path/to/Component.js"]
[@mel.module "./path/to/Component.js"]
external make: ({. "name": string}) => React.element = "default";
```

**Note on `default`:** to understand what `default` means, see [the Melange docs on ES6](https://melange.re/v2.0.0/communicate-with-javascript/#default-es6-values).
**Note on `default`:** to understand what `default` means, see [the Melange docs on ES6](https://melange.re/v4.0.0/communicate-with-javascript#default-es6-values).

## Component Naming

Expand Down
Loading
Loading