Skip to content

Commit 1b852bc

Browse files
committed
remove hardcoded require
1 parent 15c7f0d commit 1b852bc

3 files changed

+22
-5
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
> - :house: [Internal]
1111
> - :nail_care: [Polish]
1212
13+
## 0.12.3 [Unreleased]
14+
15+
#### :bug: Bug Fix
16+
17+
- Remove hardcoded `require` so it works in both common js and ES module modes. (https://github.com/rescript-lang/rescript-react/pull/117)
18+
1319
## 0.12.2
1420

1521
- Fix incorrect usage of `@uncurry`.

src/RescriptReactErrorBoundary.bs.js

+8-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RescriptReactErrorBoundary.res

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ type params<'error> = {
1010
info: info,
1111
}
1212

13+
type reactComponentClass
14+
@module("react") external component: reactComponentClass = "Component"
15+
let noOp: reactComponentClass => unit = %raw(`function (_x) {}`)
16+
let reactComponentClass = component
17+
// this is so that the compiler doesn't optimize away the previous line
18+
noOp(reactComponentClass)
19+
1320
%%raw(`
14-
var React = require("react");
1521
1622
var ErrorBoundary = (function (Component) {
1723
function ErrorBoundary(props) {
@@ -28,7 +34,7 @@ var ErrorBoundary = (function (Component) {
2834
: this.props.children;
2935
};
3036
return ErrorBoundary;
31-
})(React.Component);
37+
})(reactComponentClass);
3238
`)
3339

3440
@react.component @val

0 commit comments

Comments
 (0)