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 梳理ReactHook
- 探React HooksReactHook
- 理解 React HooksReactHook
- Why React HooksReactHook
- React Hooks (Proposal)ReactHook
- React Hooks 指北ReactHook
- 實現 React HooksReactHook
- React Hooks總結ReactHook
- 淺談React HooksReactHook
- React Hooks 的用法ReactHook
- Render Props and HooksHook
- React Hooks 札記ReactHook
- 精讀《React Hooks》ReactHook
- 擁抱 React HooksReactHook
- React Hooks 深入系列ReactHook
- React hooks實踐ReactHook
- Hooks中的useStateHook
- React Hooks的理解ReactHook
- [譯] 理解 React HooksReactHook
- Hooks概覽(譯)Hook
- react之react HooksReactHook
- React State Hooks的閉包陷阱,在使用Hooks之前必須掌握ReactHook
- ?一個簡單愉悅的 hooks 使用庫 react-hooks-easyHookReact
- React Hooks:初探·實踐ReactHook
- Flutter Hooks 使用及原理FlutterHook
- React Hooks 入門教程ReactHook
- 淺談 React Hooks(一)ReactHook
- React Hooks-概覽ReactHook
- React Hooks 使用詳解ReactHook
- 初探React Hooks & SSR改造ReactHook
- 淺談 React Hooks(二)ReactHook
- React-hooks 簡介ReactHook
- 使用 React Hooks 宣告 setIntervalReactHook
- react hooks初體驗ReactHook
- ts + hooks 的基本使用Hook