码迷,mamicode.com
首页 > 其他好文 > 详细

React Hook

时间:2019-12-09 01:08:36      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:you   ber   UNC   ++   技术   count   imp   click   func   

import React, {useState, useEffect} from ‘react‘;

function Example() {
    const [count, setCount] = useState(0);
    useEffect(() => {
        document.title = `You clicked ${count} times`;
    });

    return (
        <div>
            <p>You clicked {count} times</p>
            <button onClick={() => setCount(count + 1)}>
                Clickkk
            </button>
        </div>
    );
}

export default Example

  技术图片技术图片

 

import React, { useState } from ‘react‘

const LoginControl = (props) => {
    const [flag, setFlag] = useState(false)
    const [cnt, setCnt] = useState(0)
    const changeState = () => {
        setFlag(state => {
            return !state
        })
        setCnt(state => {
            let newCnt = state
            newCnt ++
            return newCnt
        })
    }

    let show = <h1 style={{ color: flag ? "red" : "yellow" }}>i see u</h1>
    let button = <button onClick={changeState}>clickkkk</button>

    return (
        <>
            {show}
            {button}
            <div>
                <button onClick={() => setCnt(cnt + 1)}>numberrr</button>
                <p>{cnt}</p>
            </div>
        </>
    )
}

export default LoginControl

  技术图片

 

 

 

 

React Hook

标签:you   ber   UNC   ++   技术   count   imp   click   func   

原文地址:https://www.cnblogs.com/zlrrrr/p/12008571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!