Skip to content

Commit 2452ff8

Browse files
davesnxanmonteiro
andauthored
Documentation updates for 0.16 (#864)
* Rename ReactEvent to React.Event * Delete JSX2 and record API content * Rename ReactEvent to React.Event in event.md * Adjust docs to melange with mel.attributes * Create a new section called hooks * Use React.element in clone-element * Update docs/context.md Co-authored-by: Antonio Nuno Monteiro <[email protected]> * Update docs/usereducer-hook.md Co-authored-by: Antonio Nuno Monteiro <[email protected]> * Update docs/working-with-optional-data.md Co-authored-by: Antonio Nuno Monteiro <[email protected]> * Update docs/working-with-optional-data.md Co-authored-by: Antonio Nuno Monteiro <[email protected]> * ReactDOM docs * use right link for createContext * use https://melange.re/v4.0.0 * remove duplicity for usestate and events * make melange urls references to change easily * remove reasonml.org links in favor of melange * fix testing with latest API --------- Co-authored-by: Antonio Nuno Monteiro <[email protected]>
1 parent 3ad0d01 commit 2452ff8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+448
-2083
lines changed

docs/callback-handlers.md

Lines changed: 0 additions & 113 deletions
This file was deleted.

docs/children.md

Lines changed: 0 additions & 135 deletions
This file was deleted.

docs/clone-element.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
title: cloneElement
33
---
44

5-
<aside class="warning">
6-
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>.
7-
</aside>
5+
Signature: `let cloneElement: (React.element, ~props: Js.t({..})=?, 'anyChildrenType) => React.element`
86

9-
Signature: `let cloneElement: (reactElement, ~props: Js.t({..})=?, 'anyChildrenType) => reactElement`
10-
11-
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.
7+
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.
128

139
```reason
1410
let clonedElement =
15-
ReasonReact.cloneElement(
11+
React.cloneElement(
1612
<div className="foo" />,
1713
~props={"payload": 1},
1814
[||]

docs/components.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Components
33
---
44

5-
ReasonReact uses functions and [React Hooks](https://reactjs.org/docs/hooks-intro.html) to compose the component of your application. Let's look at how a component is written and then break down some of the things happening.
5+
ReasonReact uses functions and [React Hooks](https://reactjs.org/docs/hooks-intro.html) to compose your components of your application. Let's look at how a component is written and then break down some of the things happening.
66

77
```reason
88
[@react.component]
@@ -20,10 +20,10 @@ let make = (~name) => {
2020

2121
## [@react.component]
2222

23-
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:
23+
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 JavaScript object as props which is how React works. Concretely, this attribute will generate code for you that looks like this:
2424

2525
```reason
26-
[@bs.obj]
26+
[@mel.obj]
2727
external makeProps: (~name: 'name, ~key: string=?, unit) => {. "name": 'name} = "";
2828
2929
let make = (Props) => {
@@ -39,7 +39,7 @@ let make = (Props) => {
3939
};
4040
```
4141

42-
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.
42+
It has added a new function called `makeProps` which uses [mel-obj] to create your props object. This function gets compiled away by Melange and will be replaced by object literals when used.
4343

4444
### A note on `children`
4545

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

114114
## Hand-writing components
115115

116-
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.
116+
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]`][mel-obj], or any other function that takes labelled arguments and returns a single prop object.
117117

118118
## Interop
119119

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

124124
```js
125-
const MyComponent = require('./path/to/Component.bs.js').make;
125+
const MyComponent = require('./path/to/Component.js').make;
126126

127127
<MyComponent name="Regina" />
128128
```
129129

130130
### Import from JS
131131

132-
It also works seamlessly with [`[@genType]`](https://github.com/cristianoc/genType) annotations and can be integrated with safety into TypeScript and Flow applications.
133-
134-
Using a component written in JS requires a single external to annotate the types it takes.
132+
Using a component written in JavaScript requires a single `external` to annotate the types it takes.
135133

136134
```reason
137-
[@bs.module "./path/to/Component.js"][@react.component]
135+
[@mel.module "./path/to/Component.js"] [@react.component]
138136
external make: (~name: string) => React.element = "default";
139137
```
140138

141139
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]`:
142140

143141
```reason
144-
[@bs.obj]
142+
[@mel.obj]
145143
external makeProps: (~name: 'name, ~key: string=?, unit) => {. "name": 'name} = "";
146144
147-
[@bs.module "./path/to/Component.js"]
145+
[@mel.module "./path/to/Component.js"]
148146
external make: ({. "name": string}) => React.element = "default";
149147
```
150148

151-
**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).
149+
**Note on `default`:** to understand what `default` means, see [the Melange docs on ES6][default-es6-values].
152150

153151
## Component Naming
154152

@@ -173,3 +171,6 @@ module Nested = {
173171
```
174172

175173
If you need a dynamic name for higher-order components or you would like to set your own name you can use `React.setDisplayName(make, "NameThatShouldBeInDevTools");`.
174+
175+
[mel-obj]: https://melange.re/v4.0.0/communicate-with-javascript#using-js-t-objects
176+
[default-es6-values]: https://melange.re/v4.0.0/communicate-with-javascript#default-es6-values

0 commit comments

Comments
 (0)