首页 > 其他 > 详细

React Hook

时间:2019-12-09 01:02:21      阅读:96      评论:0      收藏:0      [点我收藏+]
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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!