Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jsmithdev/8171f4b3df8aa4601a463f94bcbb687d to your computer and use it in GitHub Desktop.
Save jsmithdev/8171f4b3df8aa4601a463f94bcbb687d to your computer and use it in GitHub Desktop.
Loading moment.js in a LWC
import { LightningElement } from 'lwc';
import moment from '@salesforce/resourceUrl/moment';
import { loadScript } from 'lightning/platformResourceLoader';
export default class MomentStuffs extends LightningElement {
renderedCallback(){
Promise.all([
loadScript(this, moment + '/moment.js')
]).then(() => {
//Hey this works!
//moment() prints out stuff here in the render callback!
debugger;
})
.catch(error => {
debugger;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment