Docz: Hooks in mdx

Created on 29 Nov 2018  ·  3Comments  ·  Source: doczjs/docz

Question

Hey there,

is there a way to use react hooks within the mdx file?
I'm trying to document a modal with docz like this:

name: Modal
---

import { Playground } from 'docz'
import Modal from './Modal'
import useToggle from '../../hooks/useToggle'

# Modal

<Playground>
  const [toggleValue, toggle] = useToggle(false)
  <Modal title="Modal title" visible={toggleValue} />
  <button onClick={toggle}>Show Modal</button>
</Playground>

Most helpful comment

For sure,

<Playground>
  {() => {
    const [toggleValue, toggle] = useToggle(false)
    return (
      <>
        <Modal title="Modal title" visible={toggleValue} />
        <button onClick={toggle}>Show Modal</button>
      </>
    )
  }}
</Playground>

All 3 comments

For sure,

<Playground>
  {() => {
    const [toggleValue, toggle] = useToggle(false)
    return (
      <>
        <Modal title="Modal title" visible={toggleValue} />
        <button onClick={toggle}>Show Modal</button>
      </>
    )
  }}
</Playground>

NOTE: You can't have blank lines inside

NOTE: You can't have blank lines inside

This would be a great tip to add to the Docz docs! My search ended here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fenbka picture fenbka  ·  3Comments

merelinguist picture merelinguist  ·  3Comments

YardWill picture YardWill  ·  3Comments

nicholasess picture nicholasess  ·  3Comments

tsnolan23 picture tsnolan23  ·  3Comments