[英]Mocking react-router-dom useHistory and other hooks with jest
[英]withRouter vs react-router-dom hooks (useHistory, useLocation, useMatch)
有時我使用 withRouter 來包裝我的組件並使用history
, location
from props
,有時我使用useHistory()
, useLocation()
。 我不知道這兩種使用方式的優缺點。
您要問的不是react-router-dom
特定的,而是要問在 React 中使用HOC pattern vs using hooks
之間的區別,簡而言之,這是項目中這些值之間的決定:
您可以在這些鏈接中了解更多關於它們的信息:
https://medium.com/simply/comparison-hocs-vs-render-props-vs-hooks-55f9ffcd5dc6
https://www.robinwieruch.de/react-hooks-higher-order-components
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.