You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Referencing the propTypes object of the current class causes this warning:
Using propTypes from another component is not safe because they may be removed in production builds
I've used this pattern in numerous places to effectively say, "pass all props but those I handle":
importReactfrom'react'import{object,string}from'prop-types'import{omit}from'lodash'classWrapperextendsReact.Component{staticpropTypes={className: string,style: string,}render(){// pass everything except className and title to child componentconstchildProps=omit(this.props,Object.keys(Wrapper.propTypes))return(<divclassName={this.props.className}style={this.props.style}><div{...childProps}>
Inner content
</div></div>)}}
Is this a false positive, or is the reason for this warning still applicable when the "other" component is actually the same component? I imagine it comes down to whether Webpack/babel plugins strip it blindly, or somehow creates a closure over it if referenced within the same class. If the latter, perhaps the message could be tweaked a bit to suggest that any static reference is not safe.
I know I can use rest/spread to filter the list, but when the list is large, I've found this to be a nice alternative to a bunch of repetition.
The text was updated successfully, but these errors were encountered:
It's not a false positive; the intention is to only use the propTypes if they're explicitly exported, so that they can be safely stripped out in production.
The best approach is likely explicit repetition, or else overriding the rule in this instance.
Are you using a babel plugin to strip propTypes in production?
Referencing the
propTypes
object of the current class causes this warning:I've used this pattern in numerous places to effectively say, "pass all props but those I handle":
Is this a false positive, or is the reason for this warning still applicable when the "other" component is actually the same component? I imagine it comes down to whether Webpack/babel plugins strip it blindly, or somehow creates a closure over it if referenced within the same class. If the latter, perhaps the message could be tweaked a bit to suggest that any static reference is not safe.
I know I can use rest/spread to filter the list, but when the list is large, I've found this to be a nice alternative to a bunch of repetition.
The text was updated successfully, but these errors were encountered: