mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-28 00:43:08 +00:00
Memoize BrewRenderer
Only re-render BrewRenderer when specific props have changed. Fixes lag during scrolling, which updates the "currentPage" prop, but isn't actually used until the text is changed.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
require('./brewRenderer.less');
|
require('./brewRenderer.less');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const { useState, useRef, useCallback } = React;
|
const { useState, useRef, useCallback, memo } = React;
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
|
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
|
||||||
@@ -47,7 +47,7 @@ const BrewPage = (props)=>{
|
|||||||
const renderedPages = [];
|
const renderedPages = [];
|
||||||
let rawPages = [];
|
let rawPages = [];
|
||||||
|
|
||||||
const BrewRenderer = (props)=>{
|
const BrewRenderer = memo((props)=>{
|
||||||
props = {
|
props = {
|
||||||
text : '',
|
text : '',
|
||||||
style : '',
|
style : '',
|
||||||
@@ -224,6 +224,19 @@ const BrewRenderer = (props)=>{
|
|||||||
</Frame>
|
</Frame>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
}, arePropsEqual);
|
||||||
|
|
||||||
|
//Only re-render brewRenderer if arePropsEqual == true
|
||||||
|
function arePropsEqual(oldProps, newProps) {
|
||||||
|
return (
|
||||||
|
oldProps.text.length === newProps.text.length &&
|
||||||
|
oldProps.style.length === newProps.style.length &&
|
||||||
|
oldProps.renderer === newProps.renderer &&
|
||||||
|
oldProps.theme === newProps.theme &&
|
||||||
|
oldProps.errors === newProps.errors &&
|
||||||
|
oldProps.themeBundle === newProps.themeBundle &&
|
||||||
|
oldProps.lang === newProps.lang
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = BrewRenderer;
|
module.exports = BrewRenderer;
|
||||||
|
|||||||
Reference in New Issue
Block a user