docusaurus/packages/docusaurus-theme-live-codeblock
Alexey Pyltsyn 63bd6b9025
refactor: define own translations in other themes (#5849)
Co-authored-by: Armano <armano2@users.noreply.github.com>
2021-11-20 16:35:27 +01:00
..
src refactor: define own translations in other themes (#5849) 2021-11-20 16:35:27 +01:00
copyUntypedFiles.js refactor(live-codeblock): migrate package to TS (#5851) 2021-11-02 12:28:41 +08:00
package.json refactor: define own translations in other themes (#5849) 2021-11-20 16:35:27 +01:00
README.md docs(v2): Add READMEs to v2 packages (#4034) 2021-01-14 17:16:26 +01:00
tsconfig.json refactor(live-codeblock): migrate package to TS (#5851) 2021-11-02 12:28:41 +08: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>
  );
}
```