react-playground-iframe
Rendering the react component to the <iframe/>
Demo (Yet Develop)
Installation
yarn add react-playground-iframe
npm install react-playground-iframe --save
Quick Start
;; { const InitCode = `const {Button} = antd; function App() { const [idx,SetIdx] = React.useState(0); return ( <div> <Button type="primary" onClick={()=> SetIdx(idx+1)}>{idx}</Button> </div> ) }`; return <div> <IFrameProvider> <CodeEditor InitCode=InitCode /> <IFrame InitCode=InitCode LoadModule='antd' LoadCSS='https://unpkg.com/antd@4.2.5/dist/antd.css' /> </IFrameProvider> </div> ;}
Instead Grammar
Playground does not support import
grammar.
And If such as -
is included, it must be replaced with _
.
The following should be used:
;;;// ↓↓↓↓↓↓↓↓const useStateuseEffect = React;const IFrame = react_playground_iframe;const Button = antd;
API
<IFrame /> Props
Name | Type | Description |
---|---|---|
InitCode | string | First Render React Code in the playground. |
LoadModule | string[] | Import the NPM Module used in the playground. |
LoadCSS | string[] | Import the href used in the playground. <= <link rel="stylesheet" href=" "> |
<CodeEditor /> Props
Name | Type | Description |
---|---|---|
InitCode | string | First Render React Code in the <textarea /> |
<IFrameProvider />
;; { const IframeData = ; ;} { <IFrameProvider> /*--- IFrame Component ---*/ /*--- CodeEditor Component ---*/ <IFrameEvent /> </IFrameProvider>}