diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bb79f0..b68eb7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/src/RescriptReactErrorBoundary.bs.js b/src/RescriptReactErrorBoundary.bs.js index 3a0c291..fe5f73e 100644 --- a/src/RescriptReactErrorBoundary.bs.js +++ b/src/RescriptReactErrorBoundary.bs.js @@ -1,9 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; - var React = require("react"); +var noOp = (function (_x) {}); + +var reactComponentClass = React.Component; + +noOp(reactComponentClass); + var ErrorBoundary = (function (Component) { function ErrorBoundary(props) { Component.call(this); @@ -19,10 +24,10 @@ var ErrorBoundary = (function (Component) { : this.props.children; }; return ErrorBoundary; -})(React.Component); +})(reactComponentClass); ; var make = ErrorBoundary; exports.make = make; -/* Not a pure module */ +/* reactComponentClass Not a pure module */ diff --git a/src/RescriptReactErrorBoundary.res b/src/RescriptReactErrorBoundary.res index 7f7019c..3caa0e8 100644 --- a/src/RescriptReactErrorBoundary.res +++ b/src/RescriptReactErrorBoundary.res @@ -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) { @@ -28,7 +34,7 @@ var ErrorBoundary = (function (Component) { : this.props.children; }; return ErrorBoundary; -})(React.Component); +})(reactComponentClass); `) @react.component @val