React Study

Component vs Props Performance

Set the footer color:

Main with Props

I am the (black) footer

Main with Component

I am the (black) footer

Main with useMemo

I am the (black) footer

Main with Children

I am the (black) footer

What's happening?

All components show a red border when they re-render. Notice the differences:

  • Main with Props: When you click the increment button, only the Main component re-renders. The Footer component is created fresh each time.
  • Main with Component: When you click the increment button, both Main and Footer re-render because the footer prop changes on every render.
  • Main with useMemo: The Footer component is memoized and only re-renders when the color prop changes, not when the count changes.
  • Main with Children: Similar to passing a component, but using the children prop pattern which is more idiomatic in React.