Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend block is always empty #5

Open
Geraldf opened this issue May 20, 2022 · 3 comments
Open

frontend block is always empty #5

Geraldf opened this issue May 20, 2022 · 3 comments

Comments

@Geraldf
Copy link

Geraldf commented May 20, 2022

I tried to use it, but it looks like that the component in frontend.js (OurComponent) never gets rendered in this repo.
in the index.js the save function returns nothing
save: function () { return null }

which would explain why the block in the frontend is empty.

@Imonin
Copy link

Imonin commented Aug 14, 2022

Any solution to the block being empty?

@davulrich
Copy link

davulrich commented Aug 30, 2022

The function run before the element is rendered to the DOM.
You need to wait on window event "DOMContentLoaded."

Example:

import ReactDOM from 'react-dom'
import App from './app

window.addEventListener('DOMContentLoaded', () => {
  const rotateqDivElements = document.querySelectorAll('.rotateq-calc')
  rotateqDivElements.forEach((element) => {
    ReactDOM.render(<App />, element)
  })
})

@LearnWebCode Could you confirm it and change it in your code please?

@aczire
Copy link

aczire commented Oct 2, 2022

@Geraldf @davulrich's observation is correct. You need to wait for the DOM to load all the elements.
I tried loading the script in the footer, by enabling in_footer parameter.
wp_enqueue_script('boilerplateFrontendScript', plugin_dir_url(__FILE__) . 'build/frontend.js', array('wp-element'), "0.0.1", true); which also worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants