簡體   English   中英

你如何鍵入一個作為道具傳遞給組件的 useState 鈎子,typescript + react

[英]How do you type a useState hook that is being passed as a prop to a component, typescript+react

我有兩個組件和

現在我將一個 useState 掛鈎從 Admin 組件傳遞到 Login 組件作為 setAuth 道具

在我的管理組件中:

const Admin = () => {
  const [auth, setAuth] = useState(false);

  <Login setAuth={setAuth} />
}

我的登錄組件:

const Login = ({ setAuth }) => {
  //and then logic to set auth based on db auth from firebase
  setAuth(true)
}

如何正確鍵入作為組件傳遞給組件的 setState 掛鈎?

interface ISetAuth {
  setAuth: Dispatch<SetStateAction<boolean>>;
}

const Login = ({ setAuth }: ISetAuth) => {
  //whatever code
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM