import React, { useEffect, useState } from "react";
function logProps(WrappedComponent) {
return class extends React.Component {
componentDidUpdate(prevProps) {
console.log("inside componentDidUpdate");
}
componentDidMount() {
console.log("insideComponentDidMount");
}
render() {
return <WrappedComponent {...this.props} />;
}
};
}
const Container = (props) => {
const [name, setName] = useState("");
const handleInputChange = (value) => {
setName(value);
};
return (
<React.Fragment>
<input value={name} onChange={(e) => handleInputChange(e.target.value)} />
</React.Fragment>
);
};
export default logProps(Container);
Here the container component is wrapped inside the logProps HOC. I want to fire the component Did Update function once the input changes. I have used the same HOC as described in the official react docs.