reactjs - Is it OK to put propTypes and defaultProps as static props inside React class? -


this way i've been doing quite time now:

export default class attachmentcreator extends component {   render() {     return <div>       <raisedbutton primary label="add attachment" />     </div>   } }  attachmentcreator.proptypes = {   id: proptypes.string, }; 

but i've seen people doing way:

export default class attachmentcreator extends component {   static proptypes = {     id: proptypes.string,   };    render() {     return <div>       <raisedbutton primary label="add attachment" />     </div>   } } 

and in fact i've seen people setting initial state outside constructor well. practice? it's been bugging me, remember discussion somewhere said setting default props static not idea - don't remember why.

non-function properties not supported es2015 classes. proposal es2016. second method considerably more convenient, plugin required support syntax (theres common babel plugin it).

on other end, hand full of open source projects beginning treat proptypes typescript interfaces, or actionconstants , create separate folders/files house various component prop types , imported component.

so in summary, both syntaxes ok use. if want use strictly es2015, latter syntax not yet supported in specification.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -