uidotdev / usehooks

A collection of modern, server-safe React hooks – from the ui.dev team

Home Page:https://usehooks.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useScript should return loaded when script is already in the page

jfnault-seedbox opened this issue · comments

In my scenario, the initial execution of 'useScript' functions correctly.
However, if I navigate away from the page and return to it. because the script is already loaded, the onload wont fire and the script will remain in loading state forever

I've submitted a pull request to address this issue.
First attemps: You can view it here.

After reflection, I see an issue with this logic. It will end up returning 'ready' for a script that was returning an error the first time. For this feature, I think we will need module-scoped variables. I'll create another PR.

Updated version here.

Fixed here. We'll get a new release out soon.

Thank @tylermcginnis Ill test it today!

Tested it, work well on my side