Skip to content

Commit 9dc7946

Browse files
authored
fix: parse props.params into individual search parameters and append them to iframeParams (#130)
1 parent 300c482 commit 9dc7946

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/lib/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface LiteYouTubeProps {
3333

3434
function LiteYouTubeEmbedComponent(
3535
props: LiteYouTubeProps,
36-
ref: React.Ref<HTMLIFrameElement>
36+
ref: React.Ref<HTMLIFrameElement>,
3737
) {
3838
const [preconnected, setPreconnected] = React.useState(false);
3939
const [iframe, setIframe] = React.useState(props.alwaysLoadIframe || false);
@@ -58,6 +58,16 @@ function LiteYouTubeEmbedComponent(
5858
...(props.playlist ? { list: videoId } : {}),
5959
});
6060

61+
// parse props.params into individual search parameters and append them to iframeParams
62+
if (props.params) {
63+
const additionalParams = new URLSearchParams(
64+
props.params.startsWith("&") ? props.params.slice(1) : props.params,
65+
);
66+
additionalParams.forEach((value, key) => {
67+
iframeParams.append(key, value);
68+
});
69+
}
70+
6171
let ytUrl = props.noCookie
6272
? "https://www.youtube-nocookie.com"
6373
: "https://www.youtube.com";
@@ -171,5 +181,5 @@ function LiteYouTubeEmbedComponent(
171181
}
172182

173183
export default React.forwardRef<HTMLIFrameElement, LiteYouTubeProps>(
174-
LiteYouTubeEmbedComponent
184+
LiteYouTubeEmbedComponent,
175185
);

0 commit comments

Comments
 (0)