docusaurus/packages/docusaurus-theme-live-codeb.../README.md
Endi 5362c2cda2
refactor(v2): move livecodeblock as plugin (#1566)
* refactor(v2): move livecodeblock as plugin

* tweak from rebase

* nits

* nits

* dep
2019-06-06 15:49:11 +07:00

45 lines
842 B
Markdown

## Docusaurus Live Codeblock
You can create live code editors with a code block `live` meta string.
Install
```bash
npm i @docusaurus/theme-live-codeblock # or yarn add @docusaurus/theme-live-codeblock
```
Modify your `docusaurus.config.js`
```diff
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>
);
}
```