Skip to content

Commit 1f6bdb5

Browse files
committed
make melange urls references to change easily
1 parent 9710747 commit 1f6bdb5

File tree

8 files changed

+38
-25
lines changed

8 files changed

+38
-25
lines changed

docs/components.md

Lines changed: 10 additions & 9 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,7 +20,7 @@ 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
2626
[@mel.obj]
@@ -39,7 +39,7 @@ let make = (Props) => {
3939
};
4040
```
4141

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.
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 [`[@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.
117117

118118
## Interop
119119

@@ -129,12 +129,10 @@ const MyComponent = require('./path/to/Component.js').make;
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-
[@mel.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

@@ -148,7 +146,7 @@ external makeProps: (~name: 'name, ~key: string=?, unit) => {. "name": 'name} =
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/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].
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

docs/element-type-is-invalid.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This likely means that:
1212
- The JS component uses ES6 default export (`export default MyComponent`) (or, you forgot to export the component altogether!).
1313
- You're using Babel/Webpack to compile those ES6 modules.
1414

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:
1616

1717
```reason
1818
[@mel.module] external myJSReactClass: ReasonReact.reactClass = "./myJSReactClass";
@@ -25,3 +25,5 @@ Use:
2525
```
2626

2727
Remember that Reason doesn't have runtime type errors! So it _must_ have meant that your binding was written wrongly.
28+
29+
[default-es6-values]: https://melange.re/v4.0.0/communicate-with-javascript/#default-es6-values

docs/event.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ React.Event module contains all event types as submodules, e.g. `React.Event.For
88

99
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`.
1010

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]:
1212

1313
```reason
1414
React.Event.Form.target(event)##value;
@@ -21,3 +21,5 @@ event->React.Event.Form.target##value;
2121
```
2222

2323
More info in the [inline docs](https://github.com/reasonml/reason-react/blob/main/src/React.rei#L1) on the interface file.
24+
25+
[using-jst-objects]: https://melange.re/v4.0.0/communicate-with-javascript/#using-jst-objects

docs/installation.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ReasonReact is built to work with [Melange](https://melange.re/) and [Reason](ht
66

77
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.
88

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.
1010

1111
#### Requirements
1212

@@ -17,11 +17,11 @@ There are other alternatives available, such as [esy](https://esy.sh/) or [nix](
1717

1818
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.
1919

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.
2121

2222
## Editor Setup
2323

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].
2525

2626
- For VSCode, we recommend using the [vscode-ocaml-platform](https://github.com/ocamllabs/vscode-ocaml-platform) plugin
2727
- 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
9090

9191
## Next steps
9292
Head to the [Intro example](intro-example.md) guide for a tour of the most important Reason React concepts you will encounter every day.
93+
94+
[melange-alternative-package-managers-experimental]: https://melange.re/v4.0.0/getting-started/#alternative-package-managers-experimental
95+
[melange-geting-started]: https://melange.re/v4.0.0/getting-started/
96+
[melange-editor-integration]: https://melange.re/v4.0.0/getting-started/#editor-integration

docs/intro-example.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ if (root != null) {
3737

3838
### Using Greeting in an existing JavaScript/Typescript application
3939

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).
4141

4242
```js
4343
/* file: App.js */
@@ -53,4 +53,6 @@ export default function App() {
5353
}
5454
```
5555

56-
Make sure you check out [Examples](simple) for more!
56+
Make sure you check out [Examples](simple.md) for more!
57+
58+
[commonjs-or-es6-modules]: https://melange.re/v4.0.0/build-system/#commonjs-or-es6-modules

docs/usestate-hook.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,5 @@ let make = () => {
111111
The key is to extract the `value` from the `event` *before* we send it to
112112
`setName`. Even if React cleans up the event, we don't lose access to the
113113
value we need.
114+
115+
[melange-url-docs]: https://melange.re/v4.0.0

docs/working-with-optional-data.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ If you're coming from JavaScript, optional data can be a real pain. ReasonML rem
66

77
ReasonML uses the `option` type to represent optional data. As defined in the standard library [here](https://reasonml.github.io/api/Option.html).
88

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`.
1010

1111
### Accessing Optional Nested Data
1212

@@ -74,4 +74,7 @@ If you need to return null instead of a component:
7474
</div>;
7575
```
7676

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.
78+
79+
[melange-belt]: https://melange.re/v4.0.0/api/re/melange/Belt
80+
[melange-belt-option-get-with-default]: https://melange.re/v4.0.0/api/re/melange/Belt/Option/index.html#val-getWithDefault

website/i18n/en.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
"context": {
2424
"title": "Context"
2525
},
26+
"custom-hooks": {
27+
"title": "Custom Hooks"
28+
},
2629
"dom": {
27-
"title": "Working with DOM"
30+
"title": "ReactDOM"
2831
},
2932
"element-type-is-invalid": {
3033
"title": "Element Type is Invalid Runtime Error"
@@ -104,12 +107,6 @@
104107
"testing": {
105108
"title": "Testing ReasonReact components"
106109
},
107-
"use-state-use-effect": {
108-
"title": "useState, useEffect in a Form"
109-
},
110-
"usedebounce-custom-hook": {
111-
"title": "Custom Hooks"
112-
},
113110
"useeffect-hook": {
114111
"title": "useEffect"
115112
},

0 commit comments

Comments
 (0)