shlomo minkowicz
shlomo minkowicz

Reputation: 109

convert vanilla javascript into react hooks

I am trying to a intergrate a materialize.css Paralex plugin into my react hook functional component. how do i do that ? here is the code

document.addEventListener('DOMContentLoaded', function() {
    var elems = document.querySelectorAll('.parallax');
    var instances = M.Parallax.init(elems, options);
  });

please assist

Upvotes: 0

Views: 1018

Answers (1)

thealpha93
thealpha93

Reputation: 778

This is how you do with class components:

componentDidMount() {
  var elems = document.querySelectorAll('.parallax');
  var instances = M.Parallax.init(elems, options);
}

Functional components:

useEffect(() => {
  var elems = document.querySelectorAll('.parallax');
  var instances = M.Parallax.init(elems, options);
}, [])

Hope this is what you needed :)

Upvotes: 1

Related Questions