reactjs – @ types / prop-types / index没有默认导出

前端之家收集整理的这篇文章主要介绍了reactjs – @ types / prop-types / index没有默认导出前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用 https://github.com/facebook/prop-types

所以我也为它安装了@ types / prop-types. https://www.npmjs.com/package/@types/prop-types

但我想这个错误.
[ts]模块’“/ node_modules / @ types / prop-types / index”’没有默认导出.

我想要完成的是在withRouter文档中做了什么.
https://reacttraining.com/react-router/web/api/withRouter

例如,您在JavaScript中看到PropTypes的使用:

  1. import React from 'react'
  2. import PropTypes from 'prop-types'
  3. import { withRouter } from 'react-router'
  4.  
  5. // A simple component that shows the pathname of the current location
  6. class ShowTheLocation extends React.Component {
  7. static propTypes = {
  8. match: PropTypes.object.isrequired,location: PropTypes.object.isrequired,history: PropTypes.object.isrequired
  9. }
  10.  
  11. render() {
  12. const { match,location,history } = this.props
  13.  
  14. return (
  15. <div>You are now at {location.pathname}</div>
  16. )
  17. }
  18. }
  19.  
  20. // Create a new component that is "connected" (to borrow redux
  21. // terminology) to the router.
  22. const ShowTheLocationWithRouter = withRouter(ShowTheLocation)

对此有任何帮助表示赞赏!

您需要像这样修改import语句
  1. import * as PropTypes from 'prop-types'

这就是创建对象PropTypes,并将prop-types模块中的所有导出导入PropTypes对象.

猜你在找的React相关文章