S4-NetQuest / react-scorm-provider

Components to easily enable SCORM API communication in React projects.
MIT License
61 stars 19 forks source link

How to wait for the API to be connected #3

Closed nooxx closed 5 years ago

nooxx commented 5 years ago

Hi there,

First of all, really great wrapper that simplifies a lot of things so thank you for that.

My only issue is that I'm trying to wait for the SCORM API to be ready so I can fetch the data previously set in suspend data, any idea how to achieve this?

Thanks, Arno

JayV30 commented 5 years ago

After the SCORM API connection is made, props.sco.suspendData should be automatically populated with the suspendData from the LMS.

props.sco object can be accessed using the withScorm wrapper.

If for some reason the suspendData is not loading after the SCORM API connection is made, you can manually call props.sco.getSuspendData(), which will then update the props.sco.suspendData object.

I wrote a quick gist that might help demonstrate

Additionally, please note that the suspend data implementation in this library is opinionated - suspend data is a stringified object and will attempt to parse it as such. So if you have existing suspend data that is not a JSON.stringify()'d object, you may run in to errors.

nooxx commented 5 years ago

Brilliant, thanks!