From the course: React: Using TypeScript
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Define our state
- [Manny] Now let's create the state of our React application applying the props we've just defined. First thing we're going to do is go back to our App.tsx here and we're going to pass in this application here. We're going to create a brand-new state here outside of the class, and then make sure we define the types for that state and then pass the state into our props here. So let's go ahead and do that. So we'll create an initial state as a variable here, so initialState, and then we're going to create inside of that state, the name property, and we're going to pass Manny again. And then just to make sure that we're using different data, instead of doing this as a simple message, we're going to do a brand-new message here just to make sure that we're not working off the old data. So let's do something like TypeScript is cool. Perfect. So once we've created our state, the next stage is to define the state type. So we'll define a brand-new type by doing type. So this is how you define…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.