加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 20:43:11 所属栏目:百科 来源:网络整理
导读:我正在尝试使用 https://github.com/facebook/prop-types 所以我也为它安装了@ types / prop-types. https://www.npmjs.com/package/@types/prop-types 但我想这个错误. [ts]模块’“/ node_modules / @ 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的使用:

import React from 'react'
import PropTypes from 'prop-types'
import { withRouter } from 'react-router'

// A simple component that shows the pathname of the current location
class ShowTheLocation extends React.Component {
  static propTypes = {
    match: PropTypes.object.isRequired,location: PropTypes.object.isRequired,history: PropTypes.object.isRequired
  }

  render() {
    const { match,location,history } = this.props

    return (
      <div>You are now at {location.pathname}</div>
    )
  }
}

// Create a new component that is "connected" (to borrow redux
// terminology) to the router.
const ShowTheLocationWithRouter = withRouter(ShowTheLocation)

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读