score:3

Accepted answer

my solution would be this, referring to the react documentation regarding type checking and creating defaultprops as a static function, to get them at everytime.

class markdown extends react.component {

    static defaultprops() { 
        return {
            text : 'this comes from 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
};

score:0

don't have any experience with react, but it does seem to me you need some sort of string quoting in your 'return' function. that for javascript would certainly throw the error you're seeing.

score:1

in jsx, you need to use double quotes for passing props to elements.

you're using single quotes, which won't work and causes the error.

another mistake is enclosing your change handler in single quotes, in this case, you have to use curly braces, because it is actually a javascript argument you want react to execute, not a string.

return (
    <textarea style={style} rows="20" placeholder="// enter text here .." onchange={this.handlechange}>
        {this.props.text}
    </textarea>
);

Related Query

More Query from same tag