This article is based on the Windows 10 system environment, learning and using React: Windows 10 1. setInterval function(1) Definition The setInterval() method calls a function or evaluates an expression at a specified period (in milliseconds). (2) Examplesimport React, { Component } from 'react'; import { Radio, Button, Icon } from 'antd'; class List extends Component { constructor(props) { super(props); this.state = { online: false, }; }; handleLogin=()=>{ localStorage.setItem('username','xuzheng'); }; handleLogout=()=>{ localStorage.removeItem('username'); }; componentDidMount(){ this.timer = setInterval(() => { this.setState({ online: localStorage.username ? true : false, }) }, 1000); } componentWillUnmount() { if (this.timer != null) { clearInterval(this.timer); } } render() { return ( <div> <div> <Icon type='user' style={{marginRight:'8px'}}/> <span>{localStorage.username ? localStorage.username : 'Not logged in'}</span> </div> <div style={{marginTop:'20px'}}> <Button type='primary' onClick={this.handleLogin}>Login</Button> </div> <div style={{marginTop:'20px'}}> <Button type='primary' onClick={this.handleLogout}>Logout</Button> </div> </div> ) } } export default List; This is the end of this article about the use of setInterval function in React. For more information about the use of setInterval function in React, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to install MySQL using yum on Centos7 and achieve remote connection
>>: Tutorial on using iostat command in Linux
Table of contents Preface Motivation for Fragment...
This article shares the specific code of vue+swip...
This article example shares the specific code of ...
HTML Part Copy code The code is as follows: <!D...
Today I made a Spring Festival gold coin red enve...
Environmental Description Server system: Ubuntu 1...
This article shares the specific code of JavaScri...
Preface Under the influence of some CSS interacti...
1. Space rules Whitespace within HTML code is usu...
Table of contents 1. Repeated declaration 1.1 var...
Six steps of JDBC: 1. Register the driver 2. Get ...
Table of contents Preface 1. Common bug fixes in ...
Table of contents 1. Official Documentation 2. Cr...
This article shares the specific code of JavaScri...
Application scenario 1: Domain name-based redirec...