Skip to content

Instantly share code, notes, and snippets.

@JimmyLv
Created January 26, 2017 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimmyLv/2d9251e83aebdb85c6ffe99a20ba56d4 to your computer and use it in GitHub Desktop.
Save JimmyLv/2d9251e83aebdb85c6ffe99a20ba56d4 to your computer and use it in GitHub Desktop.

ref: https://medium.com/@fay_jai/react-elements-vs-react-components-vs-component-backing-instances-14d42729f62#.quy1wd21o

(function ($, HtmlToReact, SGReact) {
    $(function() {
        var HtmlToReactParser = HtmlToReact.Parser;
        var htmlToReactParser = new HtmlToReactParser();
        $(".carousel-container").map(function() {
            var reactComponents = [];
            $(this).children().each(function() {
                var htmlInput = this.outerHTML;
                var reactComponent = htmlToReactParser.parse(htmlInput);
                reactComponents.push(reactComponent);
            });
            // Empty the all the content inside the container
            $(this).empty();
            // Start to display the container
            $(this).show();
            var reactContainer = $(this)[0];
            ReactDOM.render(
                React.createElement(SGReact.Carousel, {}, reactComponents),
                reactContainer
            );
        });
    });
})(jQuery, HtmlToReact, SGReact);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment