Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

Commit a62876e

Browse files
alexandre-lelainrakannimer
authored andcommitted
docs(built-in, playground): added stateful section to playground docs
1 parent b3c7dbc commit a62876e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/docs/documentation/general/built-in-components.mdx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,51 @@ This can be very useful to test and develop your components in a good environmen
4343

4444
Note that you can edit the code below the components from your browser and see the changes you make be reflected live above it!
4545

46+
### Stateful components
47+
48+
The `<Playground>` component is also able to let you edit stateful and functional components:
49+
50+
```jsx
51+
import { Playground } from 'docz'
52+
53+
# Counter
54+
55+
<Playground>
56+
{() => {
57+
const [counter, setCounter] = React.useState(0)
58+
return (
59+
<>
60+
<button onClick={() => setCounter(counter => counter+1)}>
61+
Increase
62+
</button>
63+
<p>{counter}</p>
64+
</>
65+
)
66+
}}
67+
</Playground>
68+
```
69+
70+
If you wrap the previous render inside a separate `<Counter>` component, it becomes:
71+
72+
```jsx
73+
import { Playground } from 'docz'
74+
import { Counter } from './Counter'
75+
76+
# Counter
77+
78+
<Playground>
79+
{() => {
80+
const [counter, setCounter] = React.useState(0)
81+
return (
82+
<Counter
83+
value={counter}
84+
onChange={() => setCounter(counter => counter+1)}
85+
/>
86+
)
87+
}}
88+
</Playground>
89+
```
90+
4691
## Component Props
4792

4893
One of the most important things when documenting a component is to know which props it expects.

0 commit comments

Comments
 (0)