Design Patterns · Middle · Question 46 of 75
Which pattern does React.memo or a memoize(fn) function implement?
- ✓Correct answer: A caching Proxy/Decorator: the wrapper returns the previous result
- 2Abstract Factory: the wrapper creates a new component on each call
- 3Visitor: the wrapper walks through all props and changes them
Explanation
The wrapper has the same interface and intercepts the call: if the inputs haven't changed, it returns the stored result. A caching proxy is a classic application of the Proxy pattern.