forked from tanner/qotnews
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 { useParams } from 'react-router-dom';
|
||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
import localForage from 'localforage';
|
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');
|
return v.localName === 'pre' || v.localName === 'code' || (v.children?.length === 1 && v.children[0].localName === 'code');
|
||||||
};
|
};
|
||||||
|
|
||||||
const nodes = useMemo(() => {
|
const nodes = (s) => {
|
||||||
if (story && story.text) {
|
if (s && s.text) {
|
||||||
let div = document.createElement('div');
|
let div = document.createElement('div');
|
||||||
div.innerHTML = story.text;
|
div.innerHTML = s.text;
|
||||||
return div.childNodes;
|
return div.childNodes;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}, [story]);
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='article-container'>
|
<div className='article-container'>
|
||||||
@@ -94,9 +94,9 @@ function Article({ cache }) {
|
|||||||
|
|
||||||
{infoLine(story)}
|
{infoLine(story)}
|
||||||
|
|
||||||
{nodes ?
|
{nodes(story) ?
|
||||||
<div className='story-text'>
|
<div className='story-text'>
|
||||||
{Object.entries(nodes).map(([k, v]) =>
|
{Object.entries(nodes(story)).map(([k, v]) =>
|
||||||
pConv.includes(k) ?
|
pConv.includes(k) ?
|
||||||
<React.Fragment key={k}>
|
<React.Fragment key={k}>
|
||||||
{v.innerHTML.split('\n\n').map((x, i) =>
|
{v.innerHTML.split('\n\n').map((x, i) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user