Capítulo 51 de 988
In Remotion, you may fetch data from an API to use it in your video. On this page, we document recipes and best practices.
type ApiResponse = {
title: string;
description: string;
};
type MyCompProps = {
id: string;
data: ApiResponse | null;
};
const MyComp: React.FC<MyCompProps> = () => null;
export const Root: React.FC = () => {
return (
<Composition
id="MyComp"
component={MyComp}
durationInFrames={300}
fps={30}
width={1920}
height={1080}
defaultProps={{
id: "1",
data: null,
}}
calculateMetadata={async ({ props }) => {
const data = await fetch(`https://example.com/api/${props.id}`);
const json = await data.json();
return {
props: {
...props,
data: json,
},
};
}}
/>
);
};