Adding JavaScript to create a component on a Visualforce page

The JavaScript code to create a Lightning Component on a Visualforce page is as follows:

<apex:page>    <apex:includeLightning />    <div id="Lightning" />    <script>
        $Lightning.use("c:youtubesearchOutApp", function() {
          $Lightning.createComponent("c:youtubesearch",
          { },
          "Lightning",
          function(cmp) {
            // do some stuff
          });
        });
    </script></apex:page>

Notice that $Lightning.use() accepts two parameters: 

  • The name of the Lightning Out dependency application, along with its namespace.
  • A callback function. The callback function receives no arguments. This callback is usually where you call $Lightning.createComponent() to add your app to the page (see the next section, Lightning Out in a Node.js ...

Get Learning Salesforce Lightning Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.