Skip to content

Passing custom arguments to the script #9

@julesterrien

Description

@julesterrien

Hey! What do you think of including the ability to pass custom props to the scripts that could be included either as attributes of the script tag, or as a data- attributes

For eg.

<Script
url="https://someUrl.com"
customProp="customPropValue"
onCreate={onCreate}
onError={onError}
onLoad={onLoad}
/>

At quick glance, the only edit necessary would be to change createScript to grab these props and add them to the script:

createScript() {
		const { onCreate, url, ...customProps } = this.props;
		const script = document.createElement('script');

		onCreate();

		if (customProps) {
                        // to include them as script attributes
			Object.keys(customProps).forEach((prop) => {
				script.setAttribute(prop, customProps[prop]);
			});
                       // or something like script.setAttribute(`data-${prop}`, customProps[prop]);
		}

		script.src = url;
		script.async = 1;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions