nesl-archive / react-sample

[Sample] React ts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-sample

about

u can getting started with Create-React-App.

this project init follow

npx create-react-app axxon-viewer --template=typescript
cd axxon-viewer
npm i node-sass
npm i --save-dev @types/react @types/react-dom
npm i --save-dev @types/react-router @types/react-router-dom

ref

note

  • useState(): 更新值,並刷新頁面。 用法:
const [uuidString, setUuidString] = useState('')
setUuidString("123")
console.log(uuidString)
  • useRef(): 更新值,但不刷新頁面。 用法:
const countRef = useRef(0)
countRef.current +=1
console.log(countRef.current)
  • useEffect(function,[]): 訂閱[]中的值並執行 function。用法:
const [uuidString, setUuidString] = useState('')
const countRef = useRef(0)

useEffect(():void=>{
   async function fetch() {
       const response= await axios.get("http://httpbin.org/uuid")
       setUuidString(response.data["uuid"])
   }
   fetch()
}, [countRef.current])

countRef.current +=1
console.log(uuidString)

About

[Sample] React ts


Languages

Language:TypeScript 56.4%Language:HTML 24.9%Language:CSS 13.0%Language:JavaScript 5.7%