React Hook
Posted zlrrrr
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了React Hook相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章