Skip to content

Commit 97022d7

Browse files
committed
Add documentation for retaining state during markdown updates
1 parent 9f4da86 commit 97022d7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,33 @@ val markdownState = rememberMarkdownState(markdown)
158158
val markdownState = rememberMarkdownState(markdown, immediate = true)
159159
```
160160

161+
#### Retaining State During Updates
162+
163+
By default, when the markdown content changes, the component shows a loading state while parsing the
164+
new content. You can use the `retainState` parameter to keep the previous rendered content visible
165+
while the new content is being parsed:
166+
167+
```kotlin
168+
// Retain previous content during updates (avoids showing loading state)
169+
val markdownState = rememberMarkdownState(
170+
markdown,
171+
retainState = true
172+
)
173+
Markdown(markdownState)
174+
175+
// With dynamic content loading
176+
val markdownState = rememberMarkdownState(
177+
key, // key that triggers re-parsing
178+
retainState = true
179+
) {
180+
"# Dynamic content $counter"
181+
}
182+
Markdown(markdownState)
183+
```
184+
185+
This is particularly useful when content updates frequently or when you want to avoid flickering
186+
between the old content and the loading state.
187+
161188
### Lazy Loading for Large Documents
162189

163190
Since version 0.33.0, the library supports rendering large markdown documents efficiently using

0 commit comments

Comments
 (0)