Junior — Senior
46
Перерендеривание React‑компонента
Companies where asked:
Task condition
Нужно выяснить, будет ли происходить повторный рендер компонента OtherFc при изменении состояния в родительском компоненте.
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>
);