0.2.5 • Published 4 years ago

react-playground-iframe v0.2.5

Weekly downloads
22
License
MIT
Repository
github
Last release
4 years ago

react-playground-iframe

npm npm Rendering the react component to the <iframe/>

Demo (Yet Develop)

Alt Text

Installation

yarn add react-playground-iframe
npm install react-playground-iframe --save

Quick Start

import React,{useState} from 'react';
import {CodeEditor,IFrameProvider,IFrame} from 'react-playground-iframe';

function App() {
  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:

import {useState,useEffect} = 'react';
import {IFrame} = 'react-playground-iframe';
import {Button} = 'antd';
//  ↓↓↓↓↓↓↓↓
const {useState,useEffect} = React;
const {IFrame} = react_playground_iframe;
const {Button} = antd;

API

<IFrame /> Props

NameTypeDescription
InitCodestringFirst Render React Code in the playground.
LoadModulestring[]Import the NPM Module used in the playground.
LoadCSSstring[]Import the href used in the playground. <= <link rel="stylesheet" href=" ">

<CodeEditor /> Props

NameTypeDescription
InitCodestringFirst Render React Code in the <textarea />

<IFrameProvider />

import React, { useContext, useEffect } from 'react';
import { IFrameContext } from 'react-playground-iframe';

function IFrameEvent()
{
  const IframeData = useContext(IFrameContext);
  useEffect(() => {
    switch(IframeData.state)
    {
      case 'load_start':
      console.log('load_start message when <IFrame /> LoadModule Prop is added');
      break;
      case 'load_end':
      console.log('load_end message when <IFrame /> LoadModule Prop Load is ended');
      break;
      case 'load_error':
      console.log('<IFrame /> LoadModule Prop Callup Failed');
      break;
    }
  }, [IframeData.state]);
}

render() {
  <IFrameProvider>
   {/*--- IFrame Component ---*/}
   {/*--- CodeEditor Component ---*/}
   <IFrameEvent />
  </IFrameProvider>
}
0.2.5

4 years ago

0.2.4

4 years ago

0.2.1

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.9

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.2

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago