-
-
Notifications
You must be signed in to change notification settings - Fork 251
Migrate to Core #876
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
Migrate to Core #876
Changes from 4 commits
a13044c
f0b51f4
1ec5c04
c8dc2b8
6552fbc
6d659e5
8bb5c90
901c244
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,12 @@ | |
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@rescript/core": "^0.6.0", | ||
"@rescript/core": "^1.3.0", | ||
fhammerschmidt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@rescript/react": "^0.12.0", | ||
"rescript-1000": "npm:[email protected]", | ||
"rescript-1010": "npm:[email protected]", | ||
"rescript-1100": "npm:[email protected]", | ||
"rescript-1110": "npm:[email protected]-rc.8", | ||
"rescript-1110": "npm:[email protected]", | ||
"rescript-820": "npm:[email protected]", | ||
"rescript-902": "npm:[email protected]", | ||
"rescript-912": "npm:[email protected]" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,12 +56,12 @@ module FancyInput = { | |
|
||
@react.component | ||
let make = () => { | ||
let input = React.useRef(Js.Nullable.null) | ||
let input = React.useRef(Nullable.null) | ||
|
||
let focusInput = () => | ||
input.current | ||
->Js.Nullable.toOption | ||
->Belt.Option.forEach(input => input->focus) | ||
->Nullable.toOption | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 6d659e5 |
||
->Option.forEach(input => input->focus) | ||
|
||
let onClick = _ => focusInput() | ||
|
||
|
@@ -96,7 +96,7 @@ module FancyInput = { | |
<input | ||
type_="text" | ||
?className | ||
ref=?{Js.Nullable.toOption(ref)->Belt.Option.map(ReactDOM.Ref.domRef)} | ||
ref=?{Nullable.toOption(ref)->Option.map(ReactDOM.Ref.domRef)} | ||
/> | ||
children | ||
</div> | ||
|
@@ -107,10 +107,10 @@ module FancyInput = { | |
|
||
@react.component | ||
let make = () => { | ||
let input = React.useRef(Js.Nullable.null) | ||
let input = React.useRef(Nullable.null) | ||
|
||
let focusInput = () => | ||
input.current->Js.Nullable.toOption->Belt.Option.forEach(input => input->focus) | ||
input.current->Nullable.toOption->Option.forEach(input => input->focus) | ||
|
||
let onClick = _ => focusInput() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,12 +56,12 @@ More infos on direct DOM manipulation can be found in the [Refs and the DOM](./r | |
|
||
@react.component | ||
let make = () => { | ||
let inputEl = React.useRef(Js.Nullable.null) | ||
let inputEl = React.useRef(Nullable.null) | ||
|
||
let onClick = _ => { | ||
inputEl.current | ||
->Js.Nullable.toOption | ||
->Belt.Option.forEach(input => input->focus) | ||
->Nullable.toOption | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nullable.forEach There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 6d659e5 |
||
->Option.forEach(input => input->focus) | ||
} | ||
|
||
<> | ||
|
@@ -104,15 +104,15 @@ Reusing the example from our [Refs and the DOM](./refs-and-the-dom#callback-refs | |
|
||
@react.component | ||
let make = () => { | ||
let textInput = React.useRef(Js.Nullable.null) | ||
let textInput = React.useRef(Nullable.null) | ||
let setTextInputRef = element => { | ||
textInput.current = element; | ||
} | ||
|
||
let focusTextInput = _ => { | ||
textInput.current | ||
->Js.Nullable.toOption | ||
->Belt.Option.forEach(input => input->focus) | ||
->Nullable.toOption | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nullable.forEach There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 6d659e5 |
||
->Option.forEach(input => input->focus) | ||
} | ||
|
||
<div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ let value = myRef.current | |
``` | ||
|
||
The value of the ref differs depending on the type of the node: | ||
- When the ref attribute is used on an HTML element, the ref passed via `ReactDOM.Ref.domRef` receives the underlying DOM element as its current property (type of `React.ref<Js.Nullable.t<Dom.element>>`) | ||
- When the ref attribute is used on an HTML element, the ref passed via `ReactDOM.Ref.domRef` receives the underlying DOM element as its current property (type of `React.ref<Nullable.t<Dom.element>>`) | ||
- In case of interop, when the ref attribute is used on a custom class component (based on JS classes), the ref object receives the mounted instance of the component as its current (not discussed in this document). | ||
- **You may not use the ref attribute on component functions** because they don’t have instances (we don't expose JS classes in ReScript). | ||
|
||
|
@@ -83,10 +83,10 @@ This code uses a `React.ref` to store a reference to an `input` DOM node to put | |
|
||
@react.component | ||
let make = () => { | ||
let textInput = React.useRef(Js.Nullable.null) | ||
let textInput = React.useRef(Nullable.null) | ||
|
||
let focusInput = () => | ||
switch textInput.current->Js.Nullable.toOption { | ||
switch textInput.current->Nullable.toOption { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to convert to option anymore, just pattern-match directly: switch textInput.current {
| Value(dom) => dom->focus
| Null | Undefined => ()
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 6d659e5 |
||
| Some(dom) => dom->focus | ||
| None => () | ||
} | ||
|
@@ -126,7 +126,7 @@ function CustomTextInput(Props) { | |
|
||
A few things happened here, so let's break them down: | ||
|
||
- We initialize our `textInput` ref as a `Js.Nullable.null` | ||
- We initialize our `textInput` ref as a `Nullable.null` | ||
- We register our `textInput` ref in our `<input>` element with `ReactDOM.Ref.domRef(textInput)` | ||
- In our `focusInput` function, we need to first verify that our DOM element is set, and then use the `focus` binding to set the focus | ||
|
||
|
@@ -148,7 +148,7 @@ module MyComp = { | |
|
||
@react.component | ||
let make = () => { | ||
let textInput = React.useRef(Js.Nullable.null) | ||
let textInput = React.useRef(Nullable.null) | ||
|
||
// This will **not** work | ||
<MyComp ref={ReactDOM.Ref.domRef(textInput)} /> | ||
|
@@ -193,15 +193,15 @@ The example below implements a common pattern: using the ref callback to store a | |
|
||
@react.component | ||
let make = () => { | ||
let textInput = React.useRef(Js.Nullable.null) | ||
let textInput = React.useRef(Nullable.null) | ||
let setTextInputRef = element => { | ||
textInput.current = element; | ||
} | ||
|
||
let focusTextInput = _ => { | ||
textInput.current | ||
->Js.Nullable.toOption | ||
->Belt.Option.forEach(input => input->focus) | ||
->Nullable.toOption | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nullable.forEach There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 6d659e5 |
||
->Option.forEach(input => input->focus) | ||
} | ||
|
||
<div> | ||
|
@@ -261,7 +261,7 @@ module CustomTextInput = { | |
|
||
@react.component | ||
let make = () => { | ||
let textInput = React.useRef(Js.Nullable.null) | ||
let textInput = React.useRef(Nullable.null) | ||
let setInputRef = element => { textInput.current = element} | ||
|
||
<CustomTextInput setInputRef/> | ||
|
Uh oh!
There was an error while loading. Please reload this page.