chaesthetics / FrontEnd-Dev

For Meta Certification
0 stars 0 forks source link

Avoiding Re-renders Using useMemo hook #19

Open chaesthetics opened 10 months ago

chaesthetics commented 10 months ago
const App = () => {
  const a = 'hi';
  const b = 'bye';
  const value = useMemo(() => ({a, b}), [a, b]);

  return (
    <AppContext.Provider value={value}>
      <ComponentA />
    </AppContext.Provider>
  );
};

const ComponentA = React.memo(() => <ComponentB />);
const ComponentB = () => <ComponentC />;
const ComponentC = () => {
  const contextValue = useContext(AppContext);
  return null;
};