Docz: Ganchos en mdx

Creado en 29 nov. 2018  ·  3Comentarios  ·  Fuente: doczjs/docz

Pregunta

Hola,

¿Hay alguna manera de usar react hooks dentro del archivo mdx?
Estoy tratando de documentar un modal con docz como este:

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>

Comentario más útil

Con seguridad,

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

Todos 3 comentarios

Con seguridad,

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

NOTA: No puede tener líneas en blanco dentro

NOTA: No puede tener líneas en blanco dentro

¡Este sería un gran consejo para agregar a los documentos de Docz! Mi búsqueda terminó aquí.

¿Fue útil esta página
0 / 5 - 0 calificaciones

Temas relacionados

hayk94 picture hayk94  ·  3Comentarios

tsnolan23 picture tsnolan23  ·  3Comentarios

bichotll picture bichotll  ·  3Comentarios

mquandalle picture mquandalle  ·  3Comentarios

wldcordeiro picture wldcordeiro  ·  3Comentarios