DEV Community

Discussion on: Remove element from DOM in React way

jfbrennan profile image
Jordan Brennan • Edited on

I barely learned hooks before I got off the train, so I have to map all of this to Vue to see what's what...

  <div><slot v-if="visible"></slot></div>

export default {
  props: ['delay'],
  data() {
    return { visible: true }
  mounted() {
    setTimeout(() => {
      this.visible = false;
    }, this.delay);
Enter fullscreen mode Exit fullscreen mode

The only thing I'm still wondering about is what you mentioned, "we told React to skip applying an effect", but useEffect is called once, setTimeout and its callback are called effects run in a loop or something?

chilupa profile image
Pavan Chilukuri Author • Edited on

Sure, If you are familiar with React class life cycle methods, you can think of useEffect Hook as componentDidMount, componentDidUpdate, and componentWillUnmount combined. They don't run in a loop.