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
* 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]>
Copy file name to clipboardExpand all lines: docs/clone-element.md
+3-7Lines changed: 3 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,17 +2,13 @@
2
2
title: cloneElement
3
3
---
4
4
5
-
<asideclass="warning">
6
-
The Record API is in feature-freeze. For the newest features and better support going forward, please consider migrating to the new <ahref="https://reasonml.github.io/reason-react/docs/en/components">function components</a>.
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.
Copy file name to clipboardExpand all lines: docs/components.md
+14-13Lines changed: 14 additions & 13 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,10 +20,10 @@ 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:
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.
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 [`[@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.
117
117
118
118
## Interop
119
119
@@ -122,33 +122,31 @@ You don't need to use the `[@react.component]` declaration to write components.
122
122
The make function above is a normal React component, you can use it today with code like:
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.
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]`:
**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].
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");`.
0 commit comments