Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: useScript hook #113

Merged
merged 2 commits into from
Dec 15, 2022
Merged

Add: useScript hook #113

merged 2 commits into from
Dec 15, 2022

Conversation

fabiankaegy
Copy link
Member

Description of the Change

The useScript hook allows you to load dynamic script tags on the page from within your react application. This is useful for things like form / video embeds where the script url may include a specific identifier.

Usage

function BlockEdit( props ) {
    const { attributes } = props;
    const { formId } = attributes;

    const { hasLoaded, scriptElement } = useScript( `https://example.com/${formId}` );

    return (
        ...
    );
}

Closes #21

Alternate Designs

Possible Drawbacks

Verification Process

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Added useScript tag to easily load dynamic script URLs on the page

Credits

Props @Shelob9

# Conflicts:
#	README.md
#	hooks/index.js
@fabiankaegy fabiankaegy merged commit 22abf78 into develop Dec 15, 2022
@fabiankaegy fabiankaegy deleted the feature/useScript branch December 15, 2022 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add: useWithScript hook
1 participant