Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: this.setState is not a function #34

Closed
carlo-fontanos opened this issue Apr 10, 2018 · 6 comments
Closed

Uncaught TypeError: this.setState is not a function #34

carlo-fontanos opened this issue Apr 10, 2018 · 6 comments

Comments

@carlo-fontanos
Copy link

I get: Uncaught TypeError: this.setState is not a function in my browser console when typing,

I think it's referencing the evt as this.

@codeslayer1
Copy link
Owner

Can you attach the code that you are trying to use?

@carlo-fontanos
Copy link
Author

carlo-fontanos commented Apr 11, 2018

Hi,

Please see code bellow:

import React, { Component } from 'react';
import CKEditor from "react-ckeditor-component";

export default class ItemCreate extends Component {
    constructor(props) {
		super(props);
        this.state = {
            is_loading: false,
            data_single: null,
            content: null
		}
        
	}
    
    onChange(evt){
        this.setState({content: evt.editor.getData()});
        // console.log(evt.editor.getData());
    }
    
    render() {
        return (
            <div className="col-md-6 col-md-offset-3 ml-t">
                <div className="clearfix">
                    <div className="col-md-12">
                        <div className="box ml-t">
                            <div className="form-group">
                                <label htmlFor="title">What are you selling or offering?:</label>
                                <input type="text" id="title" name="title" className="form-control" />
                            </div>
                            <div className="form-group">
                                <label htmlFor="price">Description:</label>
                                <CKEditor 
                                    content={""} 
                                    events={{
                                        "change": this.onChange
                                    }}
                                />
                            </div>
                            
                            <input type="submit" className="btn btn-default" />
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}

My version:

"react": "15.5.3",
"react-ckeditor-component": "^1.0.7",

@codeslayer1
Copy link
Owner

codeslayer1 commented Apr 11, 2018

This does not seem to be an error with the component. Looks like in your onChange method, you do not have access to this. You must bind this to your onChange function. To do this, add this line in your constructor.

this.onChange = this.onChange.bind(this);

See if this helps.

@carlo-fontanos
Copy link
Author

Thank you, your solution worked for me!

@codeslayer1
Copy link
Owner

Welcome. Closing this issue.

@Abhinash1994
Copy link

I get: simple problem but i don't know how can i solve it. when i will submit the ckeditor then i got with html tag the my content .

like

what's up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants