Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Failing to Initialization JavaScript for the layout components


Hello Support Team,

Thank you for this great theme. Am failing to initialization JavaScript therefore all the modal, sidebar drop down menus are failing to work. Am developing my project in react but using the html template as a single page application.

How can I initialize or setup javascript in react ?

Thanks


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Hi Frank,

Thank you for reaching out to us.

In our HTML version, our components are initialized within the load event. However, in SPA versions, content is rendered differently, and to use our JavaScript components, you'll need to move the initialization from the load event to the useEffect hook.

All components in HTML version are initialized in js/components/_init.js, you can move this initialization into useEffect as shown below:

useEffect(() => {
KTComponents.init();
});


If you have further questions or require additional assistance, please don't hesitate to ask.

Regards,
Lauris Stepanovs,
Keenthemes Support Team



Hello Lauris,

Am getting the following error below;
'KTComponents' is not defined no-undef

Do I need to import the components folder into the page



Hi,

If you are using source JS files instead of their bundled versions, you can export all the required instances and then import them into your React component.

In the file js/components/_init.js, add the following code to export the KTComponents instance:

export KTComponents;


Then in your React component, you can import this instance as shown below:

import KTComponents from "js/components/_init.js";


If you prefer using a bundled scripts.bundle.js, you can simply add this instance to the global window scope in js/components/_init.js:

window.KTComponents = KTComponents;


Regards,
Lauris Stepanovs,
Keenthemes Support Team


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(