Check when a form-field component is loaded in React based module

thumbnail
Carlos Durán, modified 3 Years ago. New Member Posts: 21 Join Date: 11/5/14 Recent Posts

Hello,

I've created a form-field module based on React.

I want to manipulate the component with Javascript but as the code fires when DOM is ready, but the component isn't, the code doesn't work.

The problem is that I'm trying to get a DOM element this way:

document.querySelector(".slider-divisor")

I've tried putting this line in many places of the JS file (resources/META-INF/resources/slider-form-field.es.js) but the result is always null.

I've found a solution using setInterval that checks when the component 'appears' in the DOM. Then, the code is executed and setInterval stops, but I want to know if exists a way to check an event when component is loaded to execute my code instead use setinterval.

This is command I've used to create the module:

blade create -t form-field -c SliderFormField --js-framework react -p com.liferay.dynamic.data.mapping.form.field.type.slider slider-form-field

Thanks in advance.