When you are using React components you need to be able to access specific references to individual components. This is done by defining a ref . ! DOCTYPE html html head lang ="en" meta charset ="UTF-8" title React Lesson 5: Using Refs to
When you are using React components you need to be able to access specific references to individual components. This is done by defining a ref
.
<span><span>DOCTYPE html</span><span>></span> <span><span>html</span><span>></span> <span><span>head </span><span>lang</span><span>="en"</span><span>></span> <span><span>meta </span><span>charset</span><span>="UTF-8"</span><span>></span> <span><span>title</span><span>></span>React Lesson 5: Using Refs to Access Components<span></span><span>title</span><span>></span> <span></span><span>head</span><span>></span> <span><span>body</span><span>></span> <span><span>script </span><span>src</span><span>="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/react.js"</span><span>></span><span>script</span><span>></span> <span><span>script </span><span>src</span><span>="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/JSXTransformer.js"</span><span>></span><span>script</span><span>></span> <span><span>script </span><span>type</span><span>="text/jsx"</span><span>></span> <span>var</span><span> React_app </span><span>=</span><span> React.createClass({ getInitialState: </span><span>function</span><span>() { </span><span>return</span><span> { red: </span><span>128</span><span>, green: </span><span>128</span><span>, blue: </span><span>128</span><span> } }, myUpdate: </span><span>function</span><span>(){ </span><span>this</span><span>.setState({ red: </span><span>this</span><span>.refs.red.getDOMNode().value, green: </span><span>this</span><span>.refs.green.getDOMNode().value, blue: </span><span>this</span><span>.refs.blue.getDOMNode().value }); }, render: </span><span>function</span><span>() { </span><span>return</span><span> ( </span><span><span>div</span><span>></span> <span><span>Silder update</span><span>=</span><span>{</span><span>this</span><span>.myUpdate} ref</span><span>=</span><span>"</span><span>red</span><span>"</span><span>><span>/</span><span>Silder><label>{this.state.red}<span>/</span><span>label</span><span>><span>br</span><span>/</span><span>></span> <span><span>Silder update</span><span>=</span><span>{</span><span>this</span><span>.myUpdate} ref</span><span>=</span><span>"</span><span>green</span><span>"</span><span>><span>/</span><span>Silder><label>{this.state.green}<span>/</span><span>label</span><span>><span>br</span><span>/</span><span>></span> <span><span>Silder update</span><span>=</span><span>{</span><span>this</span><span>.myUpdate} ref</span><span>=</span><span>"</span><span>blue</span><span>"</span><span>><span>/</span><span>Silder><label>{this.state.blue}<span>/</span><span>label</span><span>><span>br</span><span>/</span><span>></span> <span><span>/</span><span>div></span> <span> ); } }); </span><span>var</span><span> Silder </span><span>=</span><span> React.createClass({ render: </span><span>function</span><span>(){ </span><span>return</span><span> ( </span><span><span>input type</span><span>=</span><span>"</span><span>range</span><span>"</span><span> min</span><span>=</span><span>"</span><span>0</span><span>"</span><span> max</span><span>=</span><span>"</span><span>255</span><span>"</span><span> onChange</span><span>=</span><span>{</span><span>this</span><span>.props.update}</span><span>/</span><span>></span> <span> ) } }); React.render(</span><span><span>React_app </span><span>/</span><span>>, document.body);</span> <span></span><span>script</span><span>></span> <span></span><span>body</span><span>></span> <span></span><span>html</span><span>></span></span></span></span></span></label></span></span></span></span></label></span></span></span></span></label></span></span></span></span></span></span></span></span></span></span></span></span></span>
Here we use getDOMNode() to get the html node:
<span><span>Silder </span><span>update</span><span>={this.myUpdate} </span><span>ref</span><span>="red"</span><span>></span><span>Silder</span><span>></span></span>
then get value from it:
this.refs.red.getDOMNode().value
But, if we add a div:
<span> var Silder = React.createClass({ render: function(){ return ( </span><span><span>div</span><span>></span> <span><!--</span><span> added </span><span>--></span> <span><span>input </span><span>type</span><span>="range"</span><span> min</span><span>="0"</span><span> max</span><span>="255"</span><span> onChange</span><span>={this.props.update}</span><span>/></span> <span></span><span>div</span><span>></span> <span><!--</span><span> added </span><span>--></span><span> ) } });</span></span></span>
We found it doesn't work.
The way can solve this problem is by adding another ref to the input element:
<span> var Silder = React.createClass({ render: function(){ return ( </span><span><span>div </span><span>></span> <span><span>input </span><span>type</span><span>="range"</span><span> min</span><span>="0"</span><span> max</span><span>="255"</span><span> ref</span><span>="range"</span><span> onChange</span><span>={this.props.update}</span><span>/></span> <span></span><span>div</span><span>></span><span> ) } });</span></span></span>
myUpdate: <span>function</span><span>(){ </span><span>this</span><span>.setState({ red: </span><span>this</span><span>.refs.red.refs.range.getDOMNode().value, green: </span><span>this</span><span>.refs.green.refs.range.getDOMNode().value, blue: </span><span>this</span><span>.refs.blue.refs.range.getDOMNode().value }); },</span>

在react中,canvas用于绘制各种图表、动画等;可以利用“react-konva”插件使用canvas,该插件是一个canvas第三方库,用于使用React操作canvas绘制复杂的画布图形,并提供了元素的事件机制和拖放操作的支持。

在react中,antd是基于Ant Design的React UI组件库,主要用于研发企业级中后台产品;dva是一个基于redux和“redux-saga”的数据流方案,内置了“react-router”和fetch,可理解为应用框架。

React不是双向数据流,而是单向数据流。单向数据流是指数据在某个节点被改动后,只会影响一个方向上的其他节点;React中的表现就是数据主要通过props从父节点传递到子节点,若父级的某个props改变了,React会重渲染所有子节点。

因为在react中需要利用到webpack,而webpack依赖nodejs;webpack是一个模块打包机,在执行打包压缩的时候是依赖nodejs的,没有nodejs就不能使用webpack,所以react需要使用nodejs。

在react中,forceupdate()用于强制使组件跳过shouldComponentUpdate(),直接调用render(),可以触发组件的正常生命周期方法,语法为“component.forceUpdate(callback)”。

react是组件化开发;组件化是React的核心思想,可以开发出一个个独立可复用的小组件来构造应用,任何的应用都会被抽象成一颗组件树,组件化开发也就是将一个页面拆分成一个个小的功能模块,每个功能完成自己这部分独立功能。

react和reactdom的区别是:ReactDom只做和浏览器或DOM相关的操作,例如“ReactDOM.findDOMNode()”操作;而react负责除浏览器和DOM以外的相关操作,ReactDom是React的一部分。

react与vue的虚拟dom没有区别;react和vue的虚拟dom都是用js对象来模拟真实DOM,用虚拟DOM的diff来最小化更新真实DOM,可以减小不必要的性能损耗,按颗粒度分为不同的类型比较同层级dom节点,进行增、删、移的操作。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

WebStorm Mac版
好用的JavaScript开发工具

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

禅工作室 13.0.1
功能强大的PHP集成开发环境