docusaurus/packages/docusaurus-theme-live-codeb...
Joshua Chen 6e2eb44964
refactor: unify how validateOptions is handled (#6961)
* refactor: unify how validateOptions is handled

* fix types

* fix again
2022-03-22 19:40:56 +08:00
..
src refactor: unify how validateOptions is handled (#6961) 2022-03-22 19:40:56 +08:00
.npmignore
README.md
copyUntypedFiles.mjs
package.json chore: prepare v2.0.0-beta.17 release (#6829) 2022-03-03 18:44:41 +01:00
tsconfig.client.json
tsconfig.json
tsconfig.server.json

README.md

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>
  );
}
```