React-starter-kit: jQuery script for specific component (server side rendering)

Created on 25 Aug 2016  路  7Comments  路  Source: kriasoft/react-starter-kit

If server side rendering, jQuery will not work because "jQuery need a document within a window". How would I write jQuery script with a specific component? Maybe like the way context.insertCss() work.
Would we make something named: context.insertScripts()?

question

Most helpful comment

@manhhailua in component you create componentDidMount() and componentDidUpdate(), and write jquery there (remmeber import jquery to your html.js)
example: http://semantic-ui.com/introduction/integrations.html

All 7 comments

You can only write jquery on ComponentDidMount() and componentDidUpdate().
ex: http://semantic-ui.com/introduction/integrations.html

@voquockhanh2 : the problem is that componentDidMount() does not run on server side rendering

@manhhailua : I think you cannot run Jquery on Server side, jquery need to read rendered DOM so it is client script only.

@voquockhanh2: so, should we make a new func named context.insertScripts? it does exactly what context.insertCss did.

@manhhailua : I think we only need import jquery on bottom of Html.js

@voquockhanh2: then where will you put these lines of code in a specific component?

  $(function () {
    // using jQuery
  });

@manhhailua in component you create componentDidMount() and componentDidUpdate(), and write jquery there (remmeber import jquery to your html.js)
example: http://semantic-ui.com/introduction/integrations.html

Was this page helpful?
0 / 5 - 0 ratings