zoukankan      html  css  js  c++  java
  • [React] Write a Custom State Hook in React

    Writing your own custom State Hook is not as a daunting as you think. To keep things simple, we'll refactor our text state value that uses useState and instead create a custom hook called useText.

    function useText(initialValue) {
      return useState(initialValue)
    }
    export function FeedbackCustomComponent() {
      const [text, setText] = useText('')
      useEffect(() => {
        async function getStarWarsQuote() {
          // Get initial text
          const response = await fetch(
            'https://starwars-quote-proxy-gi0d3x1lz.now.sh/api/randomQuote'
          )
          const data = await response.json()
          const quote = data.starWarsQuote
          setText(quote)
        }
        getStarWarsQuote()
      }, [setText])
  • 相关阅读:
    开始研究web,mark一下
    干掉Unity3D
    mysql NDB
    mysql federated engine
    mysql memory
    mysql merge
    mysql innodb 引擎
    mysql myisam
    mysql 的日志文件
    mysql 的数据文件
  • 原文地址:https://www.cnblogs.com/Answer1215/p/11773753.html
Copyright © 2011-2022 走看看