When does a component unmount?

前端 未结 4 541
感动是毒
感动是毒 2020-12-25 09:52

My current understanding is that a component mounts onto the DOM when it is needed to be seen or when the route requires that component. It will also render its child compon

4条回答
  •  不思量自难忘°
    2020-12-25 10:46

    I would say a component mount onto the DOM only if it's used via another component, including a Router component. Don't think of routers as special elements/things in React. They're like other components and they do a matching between current URL and the patterns they have to decide which component should be rendered via the render() function of Router. Whenever there is a change of URL, the router picks the new component to render and does rendering via render() function.

提交回复
热议问题