react-starter-kit icon indicating copy to clipboard operation
react-starter-kit copied to clipboard

jQuery script for specific component (server side rendering)

Open manhhailua opened this issue 10 years ago • 7 comments

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()?

manhhailua avatar Aug 25 '16 01:08 manhhailua

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

voquockhanh avatar Aug 25 '16 03:08 voquockhanh

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

manhhailua avatar Aug 25 '16 03:08 manhhailua

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

voquockhanh avatar Aug 25 '16 03:08 voquockhanh

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

manhhailua avatar Aug 25 '16 03:08 manhhailua

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

voquockhanh avatar Aug 25 '16 04:08 voquockhanh

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

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

manhhailua avatar Aug 25 '16 04:08 manhhailua

@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

voquockhanh avatar Aug 25 '16 04:08 voquockhanh