refactor: Refactor nodes logic from useMemo to a regular function
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect, useMemo } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { Helmet } from 'react-helmet';
|
||||
import localForage from 'localforage';
|
||||
@@ -61,14 +61,14 @@ function Article({ cache }) {
|
||||
return v.localName === 'pre' || v.localName === 'code' || (v.children?.length === 1 && v.children[0].localName === 'code');
|
||||
};
|
||||
|
||||
const nodes = useMemo(() => {
|
||||
if (story && story.text) {
|
||||
const nodes = (s) => {
|
||||
if (s && s.text) {
|
||||
let div = document.createElement('div');
|
||||
div.innerHTML = story.text;
|
||||
div.innerHTML = s.text;
|
||||
return div.childNodes;
|
||||
}
|
||||
return null;
|
||||
}, [story]);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='article-container'>
|
||||
@@ -94,9 +94,9 @@ function Article({ cache }) {
|
||||
|
||||
{infoLine(story)}
|
||||
|
||||
{nodes ?
|
||||
{nodes(story) ?
|
||||
<div className='story-text'>
|
||||
{Object.entries(nodes).map(([k, v]) =>
|
||||
{Object.entries(nodes(story)).map(([k, v]) =>
|
||||
pConv.includes(k) ?
|
||||
<React.Fragment key={k}>
|
||||
{v.innerHTML.split('\n\n').map((x, i) =>
|
||||
|
||||
Reference in New Issue
Block a user