0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AstroでStackblitz SDKを使った埋め込み用Reactコンポーネントを作る

Posted at

事前に @stackblitz/sdk はインストールしておく

import sdk from "@stackblitz/sdk";
import { useEffect } from "react";

export const StackblitzEmbed = (props: { projectID: string }) => {
  useEffect(() => {
    sdk
      .embedProjectId("stackblitz-embed", props.projectID, {
        openFile: "package.json",
      })
      .then((r) => {
        console.log(r);
      })
      .catch((e) => {
        console.error(e);
      });
  }, []);

  return (
    <div style={{ paddingTop: "15px" }}>
      <div id="stackblitz-embed">Embed Stackblitz editor</div>
    </div>
  );
};

使う側はこんな感じ

---
title: Stackblitz Demo
description: Stackblitz Demo
---
import { StackblitzEmbed } from '../../components/StackblitzEmbed'; 

## Demo

<StackblitzEmbed projectID="vitejs-vite-nrzuxh" client:only />

client:only をつけていないと動かない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?