hooks
useState
const [count, setCount] = useState(0);
const [person, setPerson] = React.useState({name: '張三瘋', age: 18,sex:"女"})
const [person, setPerson] = React.useState(() => ({name: '張三瘋', age: 18,sex:"女"}))
setCount(5);
setPerson({
...person, //拷貝之前的所有屬性
age:person.age+1,
name: '張四瘋' //這裡的name覆蓋之前的name
})
useEffect
當資料發生變化後,渲染到元件上,元件渲染完畢後,就會呼叫useEffect(函式式元件)
import React,{useState,useEffect} from 'react';
function App() {
const [count,setCount] = useState(0);
useEffect(()=>{
console.log("userEffect");
document.title = count;
});
return (
<div className="App">
<p>{count}</p>
<input type="button" value="測試" onClick={()=>{setCount(count+1)}} />
</div>
);
}
相關文章
- [react] hooksReactHook
- Redux with HooksReduxHook
- React HooksReactHook
- React Hooks (Proposal)ReactHook
- 探React HooksReactHook
- 理解 React HooksReactHook
- Render Props and HooksHook
- Why React HooksReactHook
- React Hooks 梳理ReactHook
- React Hooks 指北ReactHook
- React Hooks 札記ReactHook
- [譯] 理解 React HooksReactHook
- React Hooks 的用法ReactHook
- 精讀《React Hooks》ReactHook
- Hooks概覽(譯)Hook
- React hooks實踐ReactHook
- 淺談React HooksReactHook
- React Hooks總結ReactHook
- 實現 React HooksReactHook
- React Hooks 深入系列ReactHook
- 擁抱 React HooksReactHook
- Hooks中的useStateHook
- react之react HooksReactHook
- React Hooks的理解ReactHook
- React State Hooks的閉包陷阱,在使用Hooks之前必須掌握ReactHook
- ?一個簡單愉悅的 hooks 使用庫 react-hooks-easyHookReact
- react hooks初體驗ReactHook
- ReactJs的Hooks簡介ReactJSHook
- Reactv16.7″Hooks”-WhattoExpectReactHook
- 淺談 React Hooks(二)ReactHook
- React Hooks 實用指南ReactHook
- React Hooks 使用詳解ReactHook
- 初探React Hooks & SSR改造ReactHook
- React Hooks-概覽ReactHook
- 淺談 React Hooks(一)ReactHook
- ts + hooks 的基本使用Hook
- React — 通用hooks封裝ReactHook封裝
- React Hooks 鉤子特性ReactHook