website/docs/guides/data-driven-dependencies/introduction.mdx
import DocsRating from '@site/src/core/DocsRating'; import {FbInternalOnly, OssOnly} from 'docusaurus-plugin-internaldocs-fb/internal';
Data Driven Dependencies (3D) is a feature in Relay that allows for the dynamic loading of components based on the data being rendered. This is useful when you have multiple possible components that could be used to render a piece of data, and you want to only load the component that is actually needed.
The main benefit of using 3D is that it allows you to avoid loading unnecessary code, which can improve the performance of your application. By only loading the code for the components that are actually needed, you can reduce the overall size of your JavaScript bundle and make your application faster.
In addition to improving performance, 3D also makes it easier to manage complex rendering logic. By allowing you to define multiple possible components for a single piece of data, 3D makes it easy to handle different rendering scenarios without having to write complex conditional logic.
There are a few canonical use-cases where 3D is recommended:
Comment type that may optionally include an image. Most comments won't include this type so ideally the code for the image rendering component would only be downloaded when necessary to make the average case faster.Video type that can be rendered as a thumbnail or autoplaying video, depending on whether the user has opted into autoplaying video. Data-driven dependencies allows products to only download the code and data for the selected rendering strategy for each item.There are two types of 3D that Relay supports:
For details on how to configure Relay to support the type of 3D you need, see Configuration.
<DocsRating />