ReactJs - Uncaught TypeError: Cannot read property 'string' of undefined -
my 2 files:
app:
import react, { component } 'react'; import { nice, super_nice } './colors'; import counter './counter'; export class app extends component { render() { return ( <div> <counter increment={ 1 } color={ nice } /> <counter increment={ 5 } color={ super_nice } /> </div> ); } }
counter:
import react, { component } 'react'; class counter extends component { constructor(props) { super(props); this.state = { counter: 0 }; this.interval = setinterval(() => this.tick(), 1000); } tick() { this.setstate({ counter: this.state.counter + this.props.increment }); } componentwillunmount() { clearinterval(this.interval); } render() { return ( <h1 style={ { color: this.props.color } }> counter ( { this.props.increment } ): { this.state.counter } </h1> ); } } counter.defaultprops = { increment: 0, color: null }; counter.proptypes = { increment: react.proptypes.number.isrequired, color: react.proptypes.string.isrequired }; module.exports = counter;
i using:
"react": "^0.14.0-rc1", "eslint": "^1.3.1", "eslint-config-airbnb": "^0.1.0", "eslint-loader": "^1.0.0", "eslint-plugin-react": "^3.0.0"
i need declare proptypes satisfy eslint, receiving run-error:
"uncaught typeerror: cannot read property 'string' of undefined".
does see error?
many !
on counter proptypes, "color" react.proptypes should capitalized.
counter.proptypes = { increment: react.proptypes.number.isrequired, color: react.proptypes.string.isrequired };
Comments
Post a Comment