2016-11-21 81 views
1

我有以下的纯渲染组件:PropTypes eslint纯错误渲染功能

import React, { PropTypes } from 'react'; 
import Dropzone from 'react-dropzone'; 

export const renderDropzone = ({ name, input: { onChange } }) => { 
    return (
    <div> 
     <Dropzone 
      name={name} 
      onDrop={filesToUpload => onChange(filesToUpload)} 
     /> 
     <button type="button" className="button">Upload</button> 
    </div> 
); 
}; 

renderDropzone.PropTypes = { 
    name: PropTypes.string.isRequired, 
    input: PropTypes.object.isRequired 
}; 

但我得到的eslint以下错误:

4:34 error 'name' is missing in props validation react/prop-types 
    4:40 error 'input' is missing in props validation react/prop-types 
+0

无状态组件的静态属性被称为'propTypes',它具有小写字母“p”。 –

回答

3

只是一个错字:

renderDropzone.PropTypes = { 
    name: PropTypes.string.isRequired 
}; 

应该是:

renderDropzone.propTypes = { 
    name: PropTypes.string.isRequired 
}; 

(类属性上的小写字母'p')