Skip to content

Commit

Permalink
fix: Fix ref issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Feb 28, 2022
1 parent c88a9c0 commit e02c72b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useRef, useState } from 'react';
import React, { useMemo, useRef, useState, useImperativeHandle } from 'react';
import ReactDOM from 'react-dom';

export interface RunWebProps extends React.IframeHTMLAttributes<HTMLIFrameElement> {
Expand All @@ -13,6 +13,9 @@ export default React.forwardRef<HTMLIFrameElement, RunWebProps>((props, ref) =>
const { html = '', css, js, title = 'Demo Title', head, onLoad, ...other } = props;
const [isLoaded, setIsLoaded] = useState(false);
const frameRef = useRef<HTMLIFrameElement>(null);

useImperativeHandle(ref, () => frameRef.current as HTMLIFrameElement, [frameRef]);

const srcDoc = useMemo(() => {
setIsLoaded(false);
const jsString = js ? `<script type="text/javascript">${js}</script>` : '';
Expand Down

0 comments on commit e02c72b

Please sign in to comment.