1

I need to apply external CSS for findDomNode() returned element.

Appfile

apply_external(){
      var mydiv = document.getElementById('myelement')
      ReactDOM.findDOMNode(mydiv).style.fontSize='100px';
   }

   render() {
      return (
         <div>
            <button onClick = {this.forceUpdateHandler}>FORCE UPDATE</button>
            <h4 >Random number: {Math.random()}</h4>
            <button onClick = {this.apply_external}>FIND DOME NODE</button>
            <h2 id="myelement">FORCE UPDATE CHECKING</h2>
         </div>
      );
   }

In this case we just use simple CSS properties.My question is, i need to apply the External CSS for "mydiv" in apply_external() method.Thankyou

praveenkumar
  • 335
  • 1
  • 3
  • 12
  • you need to invalidate the component in order the force it to redraw itself? [see docs](https://facebook.github.io/react/docs/component-api.html#forceupdate) but it would be better to pass the css as props – Ello Aug 30 '16 at 07:20
  • Ello i need to apply the css properties externally ,instead of using "style.fontSize" – praveenkumar Aug 30 '16 at 07:23
  • do you meant with outside: outside of your component or outside of your react app? – Ello Aug 30 '16 at 07:27
  • outside of the component Ello – praveenkumar Aug 30 '16 at 07:29
  • then pass it as props – Ello Aug 30 '16 at 07:31
  • I didn't know how to pass CSS in props and i need to use apply CSS file for findDomNode() element in externally. – praveenkumar Aug 30 '16 at 07:35
  • I don't know what you mean by apply CSS files to a list of dom nodes but here is an [example](http://stackoverflow.com/a/34837201/1565198) on how to load css files at runtime via react. However in your question you wrote about external CSS, on your comments you write about CSS files. What do you want to achieve exactly? Apply additional stylesheets (inline), or add another stylesheet-file at runtime? Are the styles you want to apply static or dynamic? Passing stylesheet to a component via props can be done by passing an object and applying that object to "style" – Ello Aug 30 '16 at 09:10
  • Ello in my file i applied the CSS property "style.color" only.. if i need to apply multiple CSS properties like marginleft, fontsize etc... how to i do it... so i need to apply the various CSS properties externally, that's why i asked how to implement external CSS . – praveenkumar Aug 30 '16 at 11:47

0 Answers0