javascript - How to modify classname in react without using state?
滿天的星座
滿天的星座 2017-07-05 11:06:31
0
3
999

Like the title, how can we change the class directly using native js instead of using the following method in react?

滿天的星座
滿天的星座

reply all (3)
滿天的星座

{this.getDom = p}}>

... // 可以在一个事件中通过this.getDom获取当前元素,再通过className设置 this.getDom.className = class1
    三叔

    Manipulating DOM with native JS is not recommended. If you really need this capability, you can get the reference to the DOM node through ReactDOM’sfindDOMNodemethod. For example here:
    https://facebook.github.io/re...

    But this is indeed a potentially risky behavior [opening a safe door]. The operation of directly modifying the DOM through native JS is redundant, unsafe and inconsistent with React ideas. It is recommended to consider the problem to be solved in the form of JSX.

      伊谢尔伦

      There must be other ways to do it. You can consider the classnames package. The ref used upstairs is also a common method

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!