What is the benefit of using withStyles over makeStyles?

落花浮王杯 提交于 2019-12-01 14:21:33

问题


Are there different use cases for each? When should one use withStyles over makeStyles?


回答1:


The Hook API (makeStyles/useStyles) can only be used with function components.

The Higher-order component API (withStyles) can be used with either class components or function components.

They both provide the same functionality and there is no difference in the styles parameter for withStyles and makeStyles.

If you are using it with a function component, then I would recommend using the Hook API (makeStyles). withStyles has a little bit of extra overhead compared to makeStyles (and internally delegates to makeStyles).




回答2:


When should one use withStyles over makeStyles?

Probably never but here are some use (narrow) cases:

  • you are running an react version that doesn't support hooks
  • you are writing an material-ui library and want to support older mui versions (withStyles is older than makeStyles)
  • you are running an older mui version
  • you want to style an class based component, for instance if you are interested in the componentDidCatch lifecycle method.


来源:https://stackoverflow.com/questions/57697664/what-is-the-benefit-of-using-withstyles-over-makestyles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!