Skip to content

Commit

Permalink
remove hardcoded require
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnobip committed Jul 2, 2024
1 parent 15c7f0d commit 1b852bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
> - :house: [Internal]
> - :nail_care: [Polish]
## 0.12.3 [Unreleased]

#### :bug: Bug Fix

- Remove hardcoded `require` so it works in both common js and ES module modes. (https://github.com/rescript-lang/rescript-react/pull/117)

## 0.12.2

- Fix incorrect usage of `@uncurry`.
Expand Down
11 changes: 8 additions & 3 deletions src/RescriptReactErrorBoundary.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/RescriptReactErrorBoundary.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ type params<'error> = {
info: info,
}

type reactComponentClass
@module("react") external component: reactComponentClass = "Component"
let noOp: reactComponentClass => unit = %raw(`function (_x) {}`)
let reactComponentClass = component
// this is so that the compiler doesn't optimize away the previous line
noOp(reactComponentClass)

%%raw(`
var React = require("react");
var ErrorBoundary = (function (Component) {
function ErrorBoundary(props) {
Expand All @@ -28,7 +34,7 @@ var ErrorBoundary = (function (Component) {
: this.props.children;
};
return ErrorBoundary;
})(React.Component);
})(reactComponentClass);
`)

@react.component @val
Expand Down

0 comments on commit 1b852bc

Please sign in to comment.