You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/components.md
+10-9Lines changed: 10 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Components
3
3
---
4
4
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.
6
6
7
7
```reason
8
8
[@react.component]
@@ -20,7 +20,7 @@ let make = (~name) => {
20
20
21
21
## [@react.component]
22
22
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:
24
24
25
25
```reason
26
26
[@mel.obj]
@@ -39,7 +39,7 @@ let make = (Props) => {
39
39
};
40
40
```
41
41
42
-
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.
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.
43
43
44
44
### A note on `children`
45
45
@@ -113,7 +113,7 @@ Reason also always opts for the safest form of a given hook as well. So `React.u
113
113
114
114
## Hand-writing components
115
115
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]`](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.
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.
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.
**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).
149
+
**Note on `default`:** to understand what `default` means, see [the Melange docs on ES6][default-es6-values].
152
150
153
151
## Component Naming
154
152
@@ -173,3 +171,6 @@ module Nested = {
173
171
```
174
172
175
173
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");`.
Copy file name to clipboardExpand all lines: docs/element-type-is-invalid.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ This likely means that:
12
12
- The JS component uses ES6 default export (`export default MyComponent`) (or, you forgot to export the component altogether!).
13
13
- You're using Babel/Webpack to compile those ES6 modules.
14
14
15
-
This is a common mistake. Please see Melange's [Import an ES6 Default Value](https://melange.re/v4.0.0/communicate-with-javascript/#default-es6-values). Aka, instead of:
15
+
This is a common mistake. Please see Melange's [Import an ES6 Default Value][default-es6-values]. Aka, instead of:
Copy file name to clipboardExpand all lines: docs/event.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ React.Event module contains all event types as submodules, e.g. `React.Event.For
8
8
9
9
You can access their properties using the `React.Event.{{EventName}}.{{property}}` method. For example, to access the `target` property of a `React.Event.Form.t` event, you would use `React.Event.Form.target`.
10
10
11
-
Since `target` is a JavaScript Object, those are typed as [`Js.t`](https://melange.re/v4.0.0/communicate-with-javascript/#using-jst-objects). If you're accessing fields on an object, like `event.target.value`, you'd use [Melange's `##` object access FFI](https://melange.re/v4.0.0/communicate-with-javascript/#using-jst-objects):
11
+
Since `target` is a JavaScript Object, those are typed as [`Js.t`][using-jst-objects]. If you're accessing fields on an object, like `event.target.value`, you'd use [Melange's `##` object access FFI][using-jst-objects]:
Copy file name to clipboardExpand all lines: docs/installation.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ ReasonReact is built to work with [Melange](https://melange.re/) and [Reason](ht
6
6
7
7
If you want to build a new app or a new website with ReasonReact and Melange, we recommend to use a package manager such as [opam](https://opam.ocaml.org/) to download and install the required dependencies.
8
8
9
-
There are other alternatives available, such as [esy](https://esy.sh/) or [nix](https://nixos.org/). See [Melange documentation](https://melange.re/v4.0.0/getting-started/#alternative-package-managers-experimental) for details.
9
+
There are other alternatives available, such as [esy](https://esy.sh/) or [nix](https://nixos.org/). See [Melange documentation][melange-alternative-package-managers-experimental] for details.
10
10
11
11
#### Requirements
12
12
@@ -17,11 +17,11 @@ There are other alternatives available, such as [esy](https://esy.sh/) or [nix](
17
17
18
18
Melange is the toolchain that compiles Reason and OCaml to JavaScript. It integrates with dune to provide a seamless experience for building and running your project.
19
19
20
-
Follow the getting started guide on [Melange's documentation](https://melange.re/v4.0.0/getting-started/) to continue.
20
+
Follow the getting started guide on [Melange's documentation][melange-geting-started] to continue.
21
21
22
22
## Editor Setup
23
23
24
-
Since Reason is an alternative syntax for OCaml, we integrate seamlessly into the official OCaml editor toolchain. Following the recommendation from [Melange's documentation](https://melange.re/v4.0.0/getting-started/#editor-integration).
24
+
Since Reason is an alternative syntax for OCaml, we integrate seamlessly into the official OCaml editor toolchain. Following the recommendation from [Melange's documentation][melange-editor-integration].
25
25
26
26
- For VSCode, we recommend using the [vscode-ocaml-platform](https://github.com/ocamllabs/vscode-ocaml-platform) plugin
27
27
- For other editors (Emacs and Vim), we recommend using a language server client plugin of your choice, and pairing it with [ocaml-lsp](https://github.com/ocaml/ocaml-lsp).
@@ -90,3 +90,7 @@ All compiled code will live under `_build/default/{{target_name}}` folder with t
90
90
91
91
## Next steps
92
92
Head to the [Intro example](intro-example.md) guide for a tour of the most important Reason React concepts you will encounter every day.
Copy file name to clipboardExpand all lines: docs/intro-example.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ if (root != null) {
37
37
38
38
### Using Greeting in an existing JavaScript/Typescript application
39
39
40
-
It's easy to import a ReasonReact component into your existing app. After being transpiled to JS, all Reason components will have `.js` as extension by default and export a function component called `make`. You can change it with [module_systems](https://melange.re/v4.0.0/build-system/#commonjs-or-es6-modules) field inside a [`melange.emit` stanza](https://dune.readthedocs.io/en/stable/melange.html#melange-emit).
40
+
It's easy to import a ReasonReact component into your existing app. After being transpiled to JS, all Reason components will have `.js` as extension by default and export a function component called `make`. You can change it with [module_systems][commonjs-or-es6-modules] field inside a [`melange.emit` stanza](https://dune.readthedocs.io/en/stable/melange.html#melange-emit).
41
41
42
42
```js
43
43
/* file: App.js */
@@ -53,4 +53,6 @@ export default function App() {
53
53
}
54
54
```
55
55
56
-
Make sure you check out [Examples](simple) for more!
56
+
Make sure you check out [Examples](simple.md) for more!
Copy file name to clipboardExpand all lines: docs/working-with-optional-data.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ If you're coming from JavaScript, optional data can be a real pain. ReasonML rem
6
6
7
7
ReasonML uses the `option` type to represent optional data. As defined in the standard library [here](https://reasonml.github.io/api/Option.html).
8
8
9
-
Here are a few examples of how to work with optional data in ReasonML, using the [Belt](https://melange.re/v4.0.0/api/re/melange/Belt) library from `melange.belt`.
9
+
Here are a few examples of how to work with optional data in ReasonML, using the [Belt][melange-belt] library from `melange.belt`.
10
10
11
11
### Accessing Optional Nested Data
12
12
@@ -74,4 +74,7 @@ If you need to return null instead of a component:
74
74
</div>;
75
75
```
76
76
77
-
Read more about [`getWithDefault`](https://reasonml.org/apis/javascript/latest/belt/option) here.
77
+
Read more about [`getWithDefault`][melange-belt-option-get-with-default] here.
0 commit comments