Junior — Senior
Re-rendering a React component
livecode
Task condition
It is necessary to find out whether the OtherFc component will re-render when the state in the parent component changes.
import { useEffect, useState, FC, PropsWithChildren } from "react";
const OtherFc = () => {
// console.log("render");
return <div>2</div>;
};
const MainFc: FC<PropsWithChildren> = ({ children }) => {
const [state, setState] = useState(0);
console.log("state", state);
useEffect(() => {
setInterval(() => {
setState((prev) => prev + 1);
}, 1000);
}, []);
return <div>{children}</div>;
};
export const App = () => (
<MainFc>
<OtherFc />
</MainFc>
);