Why does the following code generate "Uncaught TypeError: inst.render is not a function" and I use React JS?

Uncaught TypeError: inst.render error is not a function indicating a line number

function RenderComment(){
                alert("Clicked");

                ReactDOM.render(React.createElement("div", {}, React.createElement(Comment,{})),   //the error points to this line
                        document.getElementById('content')
                );      
            } 

I also get a warning

Warning: comment (...): a method was found on the returned instance of the component render: you may have forgotten to determine whether you renderreturned null / false from the stateless component or tried to display an element, type is a function that is not a React component.

All my Jact React code

   <script type="text/babel">

    var CommentBox = React.createClass({
        var token = $("meta[name='_csrf']").attr("content");
        var header = $("meta[name='_csrf_header']").attr("content");
        var initializeScroll = 0;
        loadCommentsFromServer: function() {
            initializeScroll = initializeScroll + 5;
            var data = {
                "count": initializeScroll
            };
            $.ajax({
                url: this.props.url,
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                data: JSON.stringify(data),
                cache: false,
                beforeSend: function(xhr) {
                    xhr.setRequestHeader(header, token);
                },
                success: function(result) {
                    this.setState({
                        data: this.state.data.concat(result)
                    });
                }.bind(this),
                error: function(xhr, status, err) {
                    console.error(this.props.url, status, err.toString());
                }.bind(this)

            });
        },
        getInitialState: function() {
            window.addEventListener("scroll", this.handleScroll);
            return {
                loadingFlag: false,
                data: []
            };
        },
        componentDidMount: function() {
            this.loadCommentsFromServer();
        },
        handleScroll: function(e) {
            //this function will be triggered if user scrolls
            var windowHeight = $(window).height();
            var inHeight = window.innerHeight;
            var scrollT = $(window).scrollTop();
            var totalScrolled = scrollT + inHeight;
            alert("Heeeeey");
            if (totalScrolled + 100 > windowHeight) { //user reached at bottom
                if (!this.state.loadingFlag) { //to avoid multiple request 
                    this.setState({
                        loadingFlag: true,
                    });
                    loading("on");
                    this.loadCommentsFromServer();
                }
            }
        },

        render: function() {
            return ( < div className = "commentBox" >
                < CommentList data = {
                    this.state.data
                }
                /> < /div>

            );
        }
    });

    var CommentList = React.createClass({
        render: function() {
            var commentNodes = this.props.data.map(function(comment) {
                return ( < Comment > {
                        comment
                    } < /Comment>

                );
            });
            return ( < div className = "commentList" > {
                commentNodes
            } < /div>);
        }
    });

    var Comment = React.createClass({
        rawMarkup: function() {
            var rawMarkup = marked(this.props.children.toString(), {
                sanitize: true
            });
            return {
                __html: rawMarkup
            };
        },
        render: function() {
            return ( < div className = "comment" >
                < span dangerouslySetInnerHTML = {
                    this.rawMarkup()
                }
                /> < /div>
            )
        }
    });


    ReactDOM.render( < CommentBox url = "/myUrl/abcd" / > ,
        document.getElementById('content')
    );

    <script>

What I'm trying to do is scroll the web page (endless scroll) and download the content from the server - AJAX - a kind of thing + JQuery (for endless scroll_ + React JS. Please help me. I spent this whole weekend.

0

Source: https://habr.com/ru/post/1620492/


All Articles