2016-11-21 65 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')