[英]List of events, that cause React component to re-render
I want to know, what are events, that cause React component to re-render. 我想知道什么是导致React组件重新渲染的事件。
I couldn't find full list anywhere, it'd be great if someone writes the list of events, that cause React component to re-render. 我在任何地方都找不到完整的列表,如果有人编写事件列表,这会导致React组件重新呈现,那将是很棒的。
I always find the following reference website helpful. 我总是发现以下参考网站会有所帮助。
http://reactcheatsheet.com/ http://reactcheatsheet.com/
Filter by lifecycle events, and you can see the places where setState will trigger a rerender. 按生命周期事件进行过滤,您可以看到setState触发重新渲染的位置。
__ __
Update: you now have to filter by "misc" 更新:您现在必须按“杂项”过滤
React component is re-rendered when setState()
is called or when props
change. 调用setState()
或更改props
时,将重新渲染React组件。 You can also force re-render with forceUpdate()
您也可以使用forceUpdate()
强制重新渲染
https://facebook.github.io/react/docs/component-api.html#forceupdate https://facebook.github.io/react/docs/component-api.html#forceupdate
By default, when your component's state or props change , your component will re-render. 默认情况下,当组件的状态或道具更改时 ,组件将重新渲染。 However, if these change implicitly (eg: data deep within an object changes without changing the object itself) or if your render() method depends on some other data, you can tell React that it needs to re-run render() by calling forceUpdate() . 但是,如果这些隐式更改(例如:对象深处的数据更改而不更改对象本身),或者您的render()方法依赖于其他数据,则可以通过调用告诉React它需要重新运行render() forceUpdate() 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.