typescript 返回对象的酷技巧

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript 返回对象的酷技巧相关的知识,希望对你有一定的参考价值。

export const useModal = () => {
  const [isShowing, setIsShowing] = useState(false);
  // instead function declaration (or expression)
  function toggle() {
    setIsShowing(!isShowing);
  }


  return {
    isShowing,
    toggle: () =>  setIsShowing(!isShowing), // we can move it to return, it's looks nicer
  };
};

以上是关于typescript 返回对象的酷技巧的主要内容,如果未能解决你的问题,请参考以下文章