Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demo/frameworks/react/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/>
<link rel="stylesheet" href="../../common/index.css" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.0.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.0.0/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.3.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.3.0/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.38/browser.js"></script>

<script src="../../../dist/zoid.frameworks.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export default function configKarma(karma: Object) {
...karmaConfig,

files: [
"test/lib/react_v16.0.0.js",
"test/lib/react-dom_v16.0.0.js",
"test/lib/react_v16.3.0.js",
"test/lib/react-dom_v16.3.0.js",
"test/lib/angular.min.js",
{
pattern: "test/zoid.global.js",
Expand Down
32 changes: 22 additions & 10 deletions src/drivers/react.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @flow */
/* eslint react/no-deprecated: off, react/no-find-dom-node: off, react/display-name: off, react/no-did-mount-set-state: off, react/destructuring-assignment: off, react/prop-types: off */
/* eslint react/no-deprecated: off, react/display-name: off, react/no-did-mount-set-state: off, react/destructuring-assignment: off, react/prop-types: off */

import { extend, noop } from "@krakenjs/belter/src";

Expand All @@ -23,15 +23,11 @@ type ReactType = {|
?{ [string]: mixed },
...children: $ReadOnlyArray<ReactElementType>
) => ReactElementType,
|};

type ReactDomType = {|
findDOMNode: (typeof ReactClassType) => HTMLElement,
createRef: () => {| current: HTMLElement |},
|};

type ReactLibraryType = {|
React: ReactType,
ReactDOM: ReactDomType,
|};

export const react: ComponentDriverType<
Expand All @@ -41,16 +37,32 @@ export const react: ComponentDriverType<
*,
*
> = {
register: (tag, propsDef, init, { React, ReactDOM }) => {
register: (tag, propsDef, init, { React }) => {
if (typeof React.createRef !== "function") {
throw new TypeError(
"React version 16.3 or higher is required. createRef API is not available in this version of React."
);
}

// $FlowFixMe
return class extends React.Component {
constructor(props) {
super(props);
this.state = {};
this.containerRef = React.createRef();
}

render(): ReactElementType {
return React.createElement("div", null);
return React.createElement("div", { ref: this.containerRef });
}

componentDidMount() {
// $FlowFixMe
const el = ReactDOM.findDOMNode(this);
const el = this.containerRef.current;

if (!el) {
throw new Error("Could not find DOM element for React component");
}

const parent = init(extend({}, this.props));
parent.render(el, CONTEXT.IFRAME);
this.setState({ parent });
Expand Down
Loading