javascript - Unexpected Identifier while coding in React -
i making 'markdown previewer' using reactjs. however, stuck @ code seems me fine. error of 'unexpected identifier ='. can't seem wrap head around why displays error.
following code snippet ..
class markdown extends react.component { static defaultprops = { text : 'this comes defaultprops !' }; static proptypes = { text : react.proptypes.string.isrequired, onchange : react.proptypes.func.isrequired; }; constructor(props) { super(props); this.handlechange = this.handlechange.bind(this); } handlechange(e) { this.props.onchange(e.target.value); } render() { const style = { width : '100%', fontsize : '18px', border : '1px solid grey', padding : '20px' }; return ( <textarea style={style} rows='20' placeholder='// enter text here ..' onchange='this.handlechange'> {this.props.text} </textarea> ); } }
here project code link .. https://codepen.io/iamrkcheers/pen/oeeyvo
the error occurs @ line 67.
any appreciated. thank you.
my solution this, referring react documentation regarding type checking , creating defaultprops static function, them @ everytime.
class markdown extends react.component { static defaultprops() { return { text : 'this comes defaultprops !' }; } constructor(props) { super(props); this.handlechange = this.handlechange.bind(this); } handlechange(e) { this.props.onchange(e.target.value); } render() { const style = { width : '100%', fontsize : '18px', border : '1px solid grey', padding : '20px' }; return ( <textarea style={style} rows='20' placeholder='// enter text here ..' onchange='this.handlechange'> {this.props.text} </textarea> ); } } markdown.proptypes = { text : react.proptypes.string.isrequired, onchange : react.proptypes.func.isrequired };
Comments
Post a Comment