I need to make an equivalent for the obsolete shouldComponentUpdate react lifecycle method with react hooks.
I have a Functional Components as it's called in this article which uses React.memo() to do it.
I just couldn't understand how to prevent the re-rendring of the component if only props is returned as a unique argument.
In others React.memo() examples (as in here) there is also a nextProps which is returned besides props and which is useful to compare with props to decide wether to let re-render the component or not.
Even when i add a second argument to be returned by the component , i always got just an empty plain js object.
Such as Functional Components aren't they always stateless so they won't keep any of the component's variables's values even those instanciated with the React.useState() ? So how we are supposed to know if props have changed ?!
this is the component:
import React, { useEffect, useRef, useState, memo } from "react";
const TinyEditor = (props, nextProps) => {
return 'some jsx'
};
const MemoizedTinyEditor = memo(
TinyEditor,
(props, nextProps) => {
// if(props.prop1 === nextProps.prop1) {
// // return true if you don't need re-render
// }
console.log("TinyEditor :: MEMO!!!!!!!!!!");
return true;
}
);
export default MemoizedTinyEditor;