React.memo, useMemo, and useCallback Optimizations

Code Bushi November 14, 2019
Video Thumbnail

Code Bushi

View Channel

About

No channel description available.

Video Description

Learn how to optimize React Components using React.memo, useMemo, and useCallback hooks. Key Takeaways! 4:40 - When a Parent Component re-renders, all Child components will re-render as well. 5:30 - React.memo is a higher order component, used with functional components. React.memo will compare the previous props to the next props, and if different, will re-render the component. 6:52 - JavaScript Primitives (string, number, boolean) being passed as a prop will work fine with React.memo. 7:30 - Arrays, Objects, Functions being passed as a prop will not work with React.memo alone. You'll need to use hooks like useMemo around the Array or Object. 8:17 - In a functional component, every re-render will cause everything in the function body to be "re-created". So Arrays, Objects, and Functions will be new and different on every re-render. When these are passes to the Child Component, it will cause the Child to re-render. 8:55 - Wrapping Arrays and Objects with the useMemo hook will solve this problem. Better yet, if the dependency array is empty, you should just hoist it out of the function body. 14:24 - When passing Functions down as props, and when Functions are used in a dependency array, wrap them in the useCallback hook to avoid re-renders and prevent useEffects from firing on each re-render. 20:30 - Don't just memoize all the things. Here is the blog post by Kent about when you should use these memoization techniques: https://kentcdodds.com/blog/usememo-and-usecallback Finished Code: https://github.com/codebushi/react-memo Follow me on Twitter: https://twitter.com/HuntaroSan Dev.to: https://dev.to/changoman

You May Also Like

Upgrade Your Gaming Audio

AI-recommended products based on this video

Loading...
Bose QuietComfort Wireless Noise Cancelling Headphones, Bluetooth Over Ear Headphones with Up to 24 Hours of Battery Life, Moonlight Grey - Limited Edition

Bose QuietComfort Wireless Noise Cancelling Headphones, Bluetooth Over Ear Headphones with Up to 24 Hours of Battery Life, Moonlight Grey - Limited Edition

(12,251)
$269.00
FREE delivery Tue, Oct 14
Loading...
New SteelSeries Arctis Nova Pro for Xbox Multi-System Gaming Headset - Premium Hi-Fi Drivers - Hi-Res Audio - 360° Spatial - GameDAC Gen 2 - Quad-DAC - ClearCast Gen 2 Mic - Xbox, PC, PS5/PS4, Switch

New SteelSeries Arctis Nova Pro for Xbox Multi-System Gaming Headset - Premium Hi-Fi Drivers - Hi-Res Audio - 360° Spatial - GameDAC Gen 2 - Quad-DAC - ClearCast Gen 2 Mic - Xbox, PC, PS5/PS4, Switch

(517)
$209.41$122.65
PrimeFREE delivery Sat, Jun 14
Loading...
NEW SteelSeries Arctis Nova 3 Multi-Platform Gaming Headset - Signature Arctis Sound - ClearCast Gen 2 Mic - PC, PS5/PS4, Xbox Series X|S, Switch, Mobile

NEW SteelSeries Arctis Nova 3 Multi-Platform Gaming Headset - Signature Arctis Sound - ClearCast Gen 2 Mic - PC, PS5/PS4, Xbox Series X|S, Switch, Mobile

(9,500)
$99.98$67.37
PrimeFREE delivery Sat, Jun 14
100+ bought in past month
Loading...
Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black
Best Seller

Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black

(17,871)
$27.98$22.38
FREE delivery Tue, Oct 14 on your first order
500+ bought in past month
Loading...
Logitech G305 LIGHTSPEED Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

Logitech G305 LIGHTSPEED Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

(21,223)
$44.98
FREE delivery Tue, Oct 14
1K+ bought in past month
Loading...
Logitech K400 Plus Wireless Touch TV Keyboard With Easy Media Control and Built-in Touchpad, HTPC Keyboard for PC-connected TV, Windows, Android, Chrome OS, Laptop, Tablet - Black
Best Seller

Logitech K400 Plus Wireless Touch TV Keyboard With Easy Media Control and Built-in Touchpad, HTPC Keyboard for PC-connected TV, Windows, Android, Chrome OS, Laptop, Tablet - Black

(38,516)
$39.98$35.98
FREE delivery Thu, Sep 4
500+ bought in past month
Loading...
Logitech M185 Wireless Mouse, 2.4GHz with USB Mini Receiver, 12-Month Battery Life, 1000 DPI Optical Tracking, Ambidextrous, Compatible with PC, Mac, Laptop - Black

Logitech M185 Wireless Mouse, 2.4GHz with USB Mini Receiver, 12-Month Battery Life, 1000 DPI Optical Tracking, Ambidextrous, Compatible with PC, Mac, Laptop - Black

(43,809)
$14.99$11.99
FREE delivery Mon, Sep 22 on your first order
1K+ bought in past month
Loading...
Razer BlackShark V2 X Gaming Headset: 50mm Drivers - Cardioid Mic - Memory Foam Cushion - Lightweight- Comfortable, Noise Isolating Earcups - for PC, PS4, PS5, Switch - 3.5mm Audio Jack - Black ECOLOGO

Razer BlackShark V2 X Gaming Headset: 50mm Drivers - Cardioid Mic - Memory Foam Cushion - Lightweight- Comfortable, Noise Isolating Earcups - for PC, PS4, PS5, Switch - 3.5mm Audio Jack - Black ECOLOGO

(16,830)
$47.98$38.38
FREE delivery Sat, Nov 15
1K+ bought in past month
Loading...
Razer Universal Quick Charging Stand for Xbox Series X|S: Magnetic Secure Charging - Matches Forza Horizon 5 Limited Edition Xbox Wireless Controller - USB Powered - (Controller Sold Separately)

Razer Universal Quick Charging Stand for Xbox Series X|S: Magnetic Secure Charging - Matches Forza Horizon 5 Limited Edition Xbox Wireless Controller - USB Powered - (Controller Sold Separately)

(1,103)
$52.27$33.70
PrimeFREE delivery Sat, Jun 14
Loading...
HyperX Cloud II - Gaming Headset, 7.1 Surround Sound, Memory Foam Ear Pads, Durable Aluminum Frame, Detachable Microphone, Works with PC, PS5, PS4, Xbox Series X|S, Xbox One – Red

HyperX Cloud II - Gaming Headset, 7.1 Surround Sound, Memory Foam Ear Pads, Durable Aluminum Frame, Detachable Microphone, Works with PC, PS5, PS4, Xbox Series X|S, Xbox One – Red

(73,207)
$89.99
FREE delivery Thu, Aug 21
500+ bought in past month
Loading...
Monster Mission 300 Wireless Gaming Headset, 2.4GHz/Bluetooth Gaming Headphones,Low Latency, Stereo, Audio Location Recognition, 48H Battery Life, Suitable for PS5, PC, PS4 and Other Gaming Devices

Monster Mission 300 Wireless Gaming Headset, 2.4GHz/Bluetooth Gaming Headphones,Low Latency, Stereo, Audio Location Recognition, 48H Battery Life, Suitable for PS5, PC, PS4 and Other Gaming Devices

(29)
$59.99
FREE delivery Sat, Sep 20
200+ bought in past month
Loading...
Logitech G435 Lightspeed and Bluetooth Wireless Gaming Headset - Lightweight Over-Ear Headphones, Built-in mics, 18h Battery, Compatible with Dolby Atmos, PC, Mobile - Black

Logitech G435 Lightspeed and Bluetooth Wireless Gaming Headset - Lightweight Over-Ear Headphones, Built-in mics, 18h Battery, Compatible with Dolby Atmos, PC, Mobile - Black

(14,873)
$49.99$39.99
FREE delivery Thu, Aug 21
400+ bought in past month
Loading...
RYR Wireless Gaming Headset for Xbox Series X|S, Xbox One, PS5, PS4, Mac, Bluetooth 5.3, 3D Surround Sound, Rotatable Earmuffs, Gaming Headphones with Noise Canceling Microphones-Blackgreen

RYR Wireless Gaming Headset for Xbox Series X|S, Xbox One, PS5, PS4, Mac, Bluetooth 5.3, 3D Surround Sound, Rotatable Earmuffs, Gaming Headphones with Noise Canceling Microphones-Blackgreen

(69)
$69.99
PrimeFREE delivery Sun, Jun 15
100+ bought in past month
Loading...
Ozeino Wireless Gaming Headset for Ps5, Ps4, Switch, Ultra Stable 2.4GHz USB & Type-C, Bluetooth 5.3 Gaming Headphones with Flip Mic, 40+Hr Battery Gamer Headset for PC, Laptop, Mobile, Mac(White)
Best Seller

Ozeino Wireless Gaming Headset for Ps5, Ps4, Switch, Ultra Stable 2.4GHz USB & Type-C, Bluetooth 5.3 Gaming Headphones with Flip Mic, 40+Hr Battery Gamer Headset for PC, Laptop, Mobile, Mac(White)

(478)
$40.36
500+ bought in past month
Loading...
Monster Persona SE ANC Active Noise Cancelling Headphones, Bluetooth Headphones Over Ear with 60H Playtime, HiFi Stereo Audio, Deep Bass, Wireless Headphones for Office

Monster Persona SE ANC Active Noise Cancelling Headphones, Bluetooth Headphones Over Ear with 60H Playtime, HiFi Stereo Audio, Deep Bass, Wireless Headphones for Office

(2)
$59.99
FREE delivery Tue, Nov 11
200+ bought in past month
Loading...
Monster Persona 6th ANC Active Noise Cancelling Headphones, Bluetooth Headphones Over Ear with HiFi Stereo Audio, 60H Playtime, 3 EQ Modes, Bluetooth 6.0, Wireless Headphones for Travel Work, Black

Monster Persona 6th ANC Active Noise Cancelling Headphones, Bluetooth Headphones Over Ear with HiFi Stereo Audio, 60H Playtime, 3 EQ Modes, Bluetooth 6.0, Wireless Headphones for Travel Work, Black

(33)
$61.99
FREE delivery Sat, Nov 22
500+ bought in past month
Loading...
Bose QuietComfort Wireless Noise Cancelling Headphones, Bluetooth Over Ear Headphones with Up to 24 Hours of Battery Life, Moonlight Grey - Limited Edition

Bose QuietComfort Wireless Noise Cancelling Headphones, Bluetooth Over Ear Headphones with Up to 24 Hours of Battery Life, Moonlight Grey - Limited Edition

(12,251)
$269.00
FREE delivery Tue, Oct 14
Loading...
Monster Persona 6th ANC Active Noise Cancelling Headphones, Bluetooth Headphones Over Ear with HiFi Stereo Audio, 60H Playtime, 3 EQ Modes, Bluetooth 6.0, Wireless Headphones for Travel Work, White

Monster Persona 6th ANC Active Noise Cancelling Headphones, Bluetooth Headphones Over Ear with HiFi Stereo Audio, 60H Playtime, 3 EQ Modes, Bluetooth 6.0, Wireless Headphones for Travel Work, White

(23)
$61.99
Prime
Loading...
PC Gaming Headset Headphone Hook Holder Hanger Mount, Headphones Stand with Adjustable & Rotating Arm Clamp, Under Desk Design, Universal Fit, Built in Cable Clip Organizer EURPMASK
Best Seller

PC Gaming Headset Headphone Hook Holder Hanger Mount, Headphones Stand with Adjustable & Rotating Arm Clamp, Under Desk Design, Universal Fit, Built in Cable Clip Organizer EURPMASK

(26,414)
$9.57
FREE delivery Sat, Jun 14 on your first order
500+ bought in past month
Loading...
Bestier Small L Shaped Gaming Desk with Power Outlets, 42 inch Computer Desk with Storage Shelves Reversible Corner Gamer Desk with Monitor Stand & Headset Hooks Carbon Fiber Black

Bestier Small L Shaped Gaming Desk with Power Outlets, 42 inch Computer Desk with Storage Shelves Reversible Corner Gamer Desk with Monitor Stand & Headset Hooks Carbon Fiber Black

(1,204)
$119.99$75.81
FREE delivery Thu, Jun 26
100+ bought in past month