react-lazy-cache is a utility for lazily calculating and caching values in React components based on props. It helps avoid expensive recalculations by only recomputing when dependent props or other cached values change. The current stable version is 3.0.1, with a low release cadence (last update several years ago). It supports both a getter-based API for modern browsers and a fallback noGetters module for IE8 compatibility. Unlike alternatives like useMemo or reselect, it provides an imperative, class-based caching mechanism tailored for React class components.
npm install react-lazy-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a lazy cache with computations depending on props and other cached values.
Use constructor or getDerivedStateFromProps for initialization and getDerivedStateFromProps for prop updates.
Ensure params do not form a cycle; avoid self-referential params.
For IE8, import LazyCache from 'react-lazy-cache/noGetters' and instantiate with new.
Use noGetters module for IE8 compatibility.
Use the 'prop-types' package: import PropTypes from 'prop-types';
Initialize this.cache in the constructor or componentWillMount before receiving new props.
Check params for cycles; ensure no calculation depends on itself directly or indirectly.
Use the noGetters module: import LazyCache from 'react-lazy-cache/noGetters' and use .get() method.