M
M
marginBottom2017-09-11 15:42:51
JavaScript
marginBottom, 2017-09-11 15:42:51

How to use the prop-types package?

I install packages

"react": "^0.14.7",
"react-dom": "^0.14.7",
"prop-types": "^15.5.10",
"react-popup": "^0.8.0"

In component.jsx I import them
import React from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import Popup from 'react-popup';

ReactDOM.render(<Popup />, document.getElementById('react-popup'));

I collect all the happiness with webpack, but the browser swears at the connected bundle.js on prop-types
Warning: Failed propType: 
Calling PropTypes validators directly is not supported by the `prop-types` package. 
Use `PropTypes.checkPropTypes()` to call them.

What is the essence of this Warning? What is the package then?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2017-09-11
@maxfarseer

Most likely, the warning is that you write React.PropTypes...
A should be simple PropTypes...
. For example:

import React, { Component } from 'react'
import { PropTypes } from 'prop-types' // можно и import PropTypes from 'prop-types'
... 
ComputersList.propTypes = {
  data: PropTypes.shape({
    rows: PropTypes.array.isRequired,
    isFetching: PropTypes.bool.isRequired,
  }).isRequired,
  onlineSessions: PropTypes.array.isRequired,
  onChangeSort: PropTypes.func.isRequired,
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question