docusaurus/packages/docusaurus-theme-live-codeblock
2023-01-10 15:22:19 -05:00
..
src fix(live-codeblock): add error boundary to live code preview (#8015) 2022-10-13 17:49:27 +02:00
.npmignore misc: make copyUntypedFiles work for watch mode (#7445) 2022-05-18 19:18:32 +08:00
package.json chore: bump dependencies major versions (#8537) 2023-01-10 15:22:19 -05:00
README.md docs(v2): Add READMEs to v2 packages (#4034) 2021-01-14 17:16:26 +01:00
tsconfig.client.json refactor: make each tsconfig explicitly declare module and include/exclude (#7443) 2022-05-18 12:48:28 +08:00
tsconfig.json chore: upgrade to TS 4.7, compile with NodeNext (#7586) 2022-06-15 19:15:11 +02:00

Docusaurus Live Codeblock

You can create live code editors with a code block live meta string.

Install

npm i @docusaurus/theme-live-codeblock # or yarn add @docusaurus/theme-live-codeblock

Modify your docusaurus.config.js

module.exports = {
  ...
+ themes: ['@docusaurus/theme-live-codeblock'],
  presets: ['@docusaurus/preset-classic']
  ...
}

Example:

```jsx live
function Clock(props) {
  const [date, setDate] = useState(new Date());
  useEffect(() => {
    var timerID = setInterval(() => tick(), 1000);

    return function cleanup() {
      clearInterval(timerID);
    };
  });

  function tick() {
    setDate(new Date());
  }

  return (
    <div>
      <h2>It is {date.toLocaleTimeString()}.</h2>
    </div>
  );
}
```