В проверке реквизита отсутствует действие отправки [реакция / проп-типы] - PullRequest
0 голосов
/ 29 января 2019

Я получаю ошибку es lint, такую ​​как [eslint], getBrodcastedList отсутствует в валидации валидации [реагировать / проп-типы]

import { PropTypes } from 'react';
class HelloMessage extends React.Component {


getRequests(query) {
    this.props.getList(query);//this line  [eslint] 'getList' is missing in props validation [react/prop-types]
  }
  render() {
    return (
      <div>
        Hello {this.props.name}
      </div>
    );
  }
}

ReactDOM.render(
  <HelloMessage name="Taylor" />,
  document.getElementById('hello-example')
);

помогите мне.Как определить типы реквизита для этой ошибки es lint на -> "this.props.getList (query)"

Ответы [ 2 ]

0 голосов
/ 29 января 2019
  1. Вы должны определить синтаксис вашей функции ES6, чтобы иметь возможность доступа к this.props, this.state внутри:
    Измените "getRequests (query) {...}" на "getRequests = (query) => {...} "

  2. Определите PropsType для вашего компонента:

HelloMessage.propTypes = {      
    getList: PropTypes.func.isRequired
};

Проверка типов с помощью PropTypes

0 голосов
/ 29 января 2019

Вам необходимо добавить propTypes для метода getList.

import PropTypes from 'prop-types';

class HelloMessage extends React.Component {

getRequests(query) {
    this.props.getList(query);//this line  [eslint] 'getList' is missing in props validation [react/prop-types]
  }
  render() {
    return (
      <div>
        Hello {this.props.name}
      </div>
    );
  }
}

HelloMessage.propTypes = {
  getList: PropTypes.func.isRequired,
};

Примечание. Для него необходимо установить еще один пакет prop-types.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...