使用迷你图时的警告控制台 - Reactjs

时间:2016-10-31 09:19:52

标签: reactjs sparklines

面对有关Sparklines道具的控制台警告..

警告:您正在为color上的SparklinesLine道具手动调用React.PropTypes验证函数。这已弃用,不适用于下一个主要版本。由于第三方PropTypes库,您可能会看到此警告。

请查看代码

import React, {Component} from 'react';
    import {Sparklines, SparklinesLine, SparklinesBars} from 'react-sparklines';

export default (props) => {
  return(
      <Sparklines data={props.data}>
        <SparklinesLine color={props.color}/>
      </Sparklines>
  );
}

1 个答案:

答案 0 :(得分:2)

它与从生产中删除的// Not supported! var error = apiShape(json, 'response'); 有关。

他们有一个令人难以置信的帖子解释了所有这些 - https://facebook.github.io/react/warnings/dont-call-proptypes.html

这是一般性的想法 -

  

在React的未来主要版本中,实现PropType验证功能的代码将在生产中被剥离。一旦发生这种情况,任何手动调用这些函数的代码(在生产中都不会被剥离)都会引发错误。

PropTypes

他们建议查看堆栈跟踪,了解export default function deprecated(propType, explanation) { return function validate(props, propName, componentName) { if (props[propName] != null) { const message = `"${propName}" property of "${componentName}" has been deprecated.\n${explanation}`; if (!warned[message]) { warning(false, message); warned[message] = true; } } return propType(props, propName, componentName); }; } api的确切位置 -

  

检查警告产生的堆栈跟踪。您将找到负责PropTypes直接调用的组件定义。

该帖还提供了修复误报的建议 -

  

如果您是第三方PropTypes库的作者,并且让消费者包装现有的React PropTypes,他们可能会开始看到来自您的库的此警告。这是因为React没有看到&#34;秘密&#34;它传递给检测手动PropTypes调用的最后一个参数。

...rest

您可以在函数中使用export default function deprecated(propType, explanation) { return function validate(props, propName, componentName, ...rest) { // Note ...rest here if (props[propName] != null) { const message = `"${propName}" property of "${componentName}" has been deprecated.\n${explanation}`; if (!warned[message]) { warning(false, message); warned[message] = true; } } return propType(props, propName, componentName, ...rest); // and here }; } 修复上述代码 - 请参阅下文 -

Sparklines

所以这可能是直接使用display: inline-block; max-width:290px; lib,或者是代码中的某个地方。如果没有完整的堆栈跟踪,就不能说,但这可以让你更接近解决问题。