TypeScript Notları
  • Giriş
  • Handbook
    • TypeScript nedir, ne işe yarar ?
    • Kurulum ve tsc
    • Temel Tipler
    • any ve unknown
    • Union Type (Çoklu Tipler)
    • Literal Types
    • Objects (Objeler)
    • Arrays (Diziler)
    • Tuple
    • Fonksiyonlar
    • Optional Params (Opsiyonel Parametreler)
    • type
    • interface
    • readonly
    • Generics
    • Modül Yapısı
    • Type Assertion
    • keyof, typeof
    • Mapped Types
    • React ve TypeScript
      • Props Tipleri
      • State Tipleri
      • Event Tipleri
      • useRef
  • Tip and Tricks
    • json2ts
  • Kaynakça
Powered by GitBook
On this page
  1. Handbook
  2. React ve TypeScript

State Tipleri

useState ile state oluşturduğumuzda, initialState değerimizin tipi state imizin otomatik olarak tipi olacaktır. Tip tanımlamak istendiği taktirde useState<tip> şeklinde tip tanımlaması yapılabilir. State tipinin tanımlaması aşağıdaki gibi olucaktır.

const [counter, setCounter] = useState(0);
/* Tip tanimlamasi yapmadigimiz takdirte initalState
degerimiziz number tipinde oldugu icin counter tipi
number olacaktir.*/

const [name, setName] = useState<string>('');
/* useState<string> ile name statenin tipi string
olarak tanimlanmistir*/

PreviousProps TipleriNextEvent Tipleri

Last updated 3 years ago