我可以在无状态组件中调用forceUpdate吗? [英] Can I call forceUpdate in stateless component?
本文介绍了我可以在无状态组件中调用forceUpdate吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个无状态组件,我想重新渲染它。我怎么能这样做?我尝试使用 forceUpdate
,但它没有用。
I have a stateless component, and I want to re-render it. How can I do so? I tried using forceUpdate
, but it did not work.
我可以改用forUpdate吗?或者其他什么?
Can I use forUpdate instead, or something else?
推荐答案
不,你不能,State-Less组件只是普通的函数
返回 jsx
,您没有任何访问React生命周期方法的权限,因为您没有从 React.Component扩展
。
No you can't, State-Less components are just normal functions
that returns jsx
, you don't have any access to the React life cycle methods as you are not extending from the React.Component
.
这篇关于我可以在无状态组件中调用forceUpdate吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文