30 seconds of react native
1.0.0

策划的有用的反应片段收集,您可以在30秒或更短的时间内理解。
注意:此存储库与原始代码的原始代码无隶属关系,是基于30秒的React,但与此均无隶属关系
要将片段导入您的项目,您必须导入React并复制组件的JavaScript代码:
import React from 'react' ;
function MyComponent ( props ) {
/* ... */
}如果与您的组件相关的任何样式,请将其复制到具有相同名称和适当扩展名的新文件,然后以这样的方式导入:
import './MyComponentStyle' ; 呈现一个股票组件。
React.useState()钩将ticker状态变量初始化为0 。tick和reset ,它们将分别基于interval和重置interval定期增加timer 。<Button>元素返回<View> ,每个元素分别调用tick并reset 。 function Ticker ( props ) {
const [ ticker , setTicker ] = React . useState ( 0 ) ;
let interval = null ;
const tick = ( ) => {
reset ( ) ;
interval = setInterval ( ( ) => {
if ( ticker < props . times ) setTicker ( ticker + 1 ) ;
else clearInterval ( interval ) ;
} , props . interval ) ;
} ;
const reset = ( ) => {
setTicker ( 0 ) ;
clearInterval ( interval ) ;
} ;
return (
< View >
< Text style = { { fontSize : 100 } } > { ticker } </ Text >
< Button onPress = { tick } title = "Tick!" />
< Button onPress = { reset } title = "Reset!" />
</ View >
) ;
} < Ticker times = { 5 } interval = { 1000 } />
⬆回到顶部
该存储库是一项正在进行的工作。如果您想做出贡献,请检查公开问题,以查看在哪里以及如何提供帮助!
此读数是使用Markdown-Builder构建的。