gpt4 book ai didi

javascript - 'react' 导出的函数

转载 作者:行者123 更新时间:2023-12-03 02:52:18 25 4
gpt4 key购买 nike

import React, { PropTypes } from 'react'

如何查看“react”导出的所有函数?

我查看了 node_modules/dist/react.js 内的文件 react.js 但找不到任何类似 module.exports = PropTypes ;< 的语句...

最佳答案

我正在检查旧版本的 react (15.4.1) 库。

它导出./lib/React

./lib/React.js 文件有 module.exports = React;

同一文件中的

React对象定义为:

var React = {

// Modern

Children: {
map: ReactChildren.map,
forEach: ReactChildren.forEach,
count: ReactChildren.count,
toArray: ReactChildren.toArray,
only: onlyChild
},

Component: ReactComponent,
PureComponent: ReactPureComponent,

createElement: createElement,
cloneElement: cloneElement,
isValidElement: ReactElement.isValidElement,

// Classic

PropTypes: ReactPropTypes,
createClass: ReactClass.createClass,
createFactory: createFactory,
createMixin: function (mixin) {
// Currently a noop. Will be used to validate and trace mixins.
return mixin;
},

// This looks DOM specific but these are actually isomorphic helpers
// since they are just generating DOM strings.
DOM: ReactDOMFactories,

version: ReactVersion,

// Deprecated hook for JSX spread, don't use this for anything.
__spread: __spread
};

在这里我可以看到它包含 PropTypes 属性,可以使用 import {PropTypes} from 'react' 导入该属性。

<小时/>

注意:

React.PropTypes has moved into a different package since React v15.5. Please use the prop-types library instead.

来源:https://reactjs.org/docs/typechecking-with-proptypes.html

关于javascript - 'react' 导出的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47792103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com