mirror of
https://github.com/dergigi/boris.git
synced 2026-01-03 15:04:24 +01:00
fix: move readingStats hook before early returns
- Fixes React Hooks order violation - All hooks must be called unconditionally in the same order - Moved readingStats useMemo before the conditional returns - Resolves 'Rendered more hooks than during the previous render' error
This commit is contained in:
@@ -152,6 +152,17 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
||||
return markdown
|
||||
}, [markdown, relevantHighlights])
|
||||
|
||||
// Calculate reading time from content (must be before early returns)
|
||||
const readingStats = useMemo(() => {
|
||||
const content = markdown || html || ''
|
||||
if (!content) return null
|
||||
// Strip HTML tags for more accurate word count
|
||||
const textContent = content.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ')
|
||||
return readingTime(textContent)
|
||||
}, [html, markdown])
|
||||
|
||||
const hasHighlights = relevantHighlights.length > 0
|
||||
|
||||
if (!selectedUrl) {
|
||||
return (
|
||||
<div className="reader empty">
|
||||
@@ -171,17 +182,6 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
||||
)
|
||||
}
|
||||
|
||||
const hasHighlights = relevantHighlights.length > 0
|
||||
|
||||
// Calculate reading time from content
|
||||
const readingStats = useMemo(() => {
|
||||
const content = markdown || html || ''
|
||||
if (!content) return null
|
||||
// Strip HTML tags for more accurate word count
|
||||
const textContent = content.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ')
|
||||
return readingTime(textContent)
|
||||
}, [html, markdown])
|
||||
|
||||
return (
|
||||
<div className="reader">
|
||||
{title && (
|
||||
|
||||
Reference in New Issue
Block a user