Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
React lazy implementation
import React from "react";
let IDS = 0;
const loaded = {};
export const lazy = modulePathResolver => {
const id = IDS++;
return props => {
const LoadedComponent = loaded[id];
if (LoadedComponent) {
return <LoadedComponent {...props} />;
}
throw modulePathResolver().then(lazyModule => {
const Component = lazyModule.default;
loaded[id] = Component;
});
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.