Solid
The JS/TS SDK can be used directly in Solid components without the need for any wrappers.
Installation
Please refer to the SDK installation section.
Usage
This is an example of using the LiveCodes TS SDK in a Solid component:
App.tsx
import { onCleanup } from 'solid-js';
import { createPlayground, type Playground, type EmbedOptions } from 'livecodes';
export default function App() {
let playground: Playground | null = null;
const options: EmbedOptions = {
params: {
html: '<h1>Hello World!</h1>',
css: 'h1 {color: blue;}',
js: 'console.log("Hello, Solid!")',
console: 'open',
},
};
const onMounted = (container: HTMLElement) => {
createPlayground(container, options).then((sdk) => {
playground = sdk; // now the SDK is available
});
};
onCleanup(() => playground?.destroy());
return <div ref={onMounted}></div>;
}
Embed options, SDK methods and TypeScript types are available as described in the JS/TS SDK documentations.