Skip to content

Instantly share code, notes, and snippets.

@mpossumato-netflix
Created September 17, 2021 23:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mpossumato-netflix/88fc729716a90ba2dd756fe24f38b12b to your computer and use it in GitHub Desktop.
Save mpossumato-netflix/88fc729716a90ba2dd756fe24f38b12b to your computer and use it in GitHub Desktop.
An example approach to leveraging Lattice in a Front End React App
import { Pluggable, PluginHost, usePluggableState } from '@netflix-internal/rgt-components/lib/lattice';
import { getDefaultRoutes } from '../routes';
import { Content, Header, Router } from './components';
import { useFetchPluginConfiguration } from './hooks';
export const App = ({ appName }: { appName: string }) => {
// Fetch plugin host configuration remotely for this application
const config = useFetchPluginConfiguration(appName);
// Allow for routes to be extended by plugins
const routes = usePluggableState('AppRoutes', null, getDefaultRoutes());
return (
<PluginHost {...config}>{/* Host will load remote modules */}
<Router routes={routes}>
<Header appName={appName} links={routes} />
<Pluggable identifier="AppContent">{/* Plugins can override these children */}
<Content />
</Pluggable>
</Router>
</PluginHost>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment