user308553
user308553

Reputation: 1250

cannot get Foundation menu to work with reactJS

I cant figure out why the following code wont create the foundation menu for me. Below is the super simplified version of my code:

        var MenuDisplay = React.createClass({

            render: function(){
                console.log("menu display render");
                var menu = (true)?
                <ul className="dropdown menu" data-dropdown-menu>
                            <li>
                                <a id="profile_name">Welcome
                                </a><ul className="menu">
                                    <li>profile</li>
                                    <li className="logout">logout</li>
                                </ul>
                            </li>
                        </ul>
                        : null;
                return(
        <div>
                    {menu}
                    <FoundationPlugin />
                    </div>
                )
            }
        });

        var FoundationPlugin = React.createClass({
            render: function(){
                //applying foundation() the whole document 
                $(document).foundation();
                return(
                    <div></div>
                );
            }
        });

        React.render(
            <MenuDisplay />,
            document.getElementById('myDiv')
        );

Upvotes: 1

Views: 721

Answers (1)

dannyjolie
dannyjolie

Reputation: 11339

React components have several lifecycle functions. If you need to wait for rendering to be done, and the actual DOM to be updated, then componentDidMount is what you need.

var MenuDisplay = React.createClass({
  componentDidMount: function(){
    // Do stuff that relies on your DOM being rendered here.
    // Usually anything related to external libs like jQuery etc.
  },
  render: function(){
    ....
    ....
  }
})

Hope this helps.

Upvotes: 2

Related Questions