From the course: React: Using TypeScript (2019)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Class/stateful component syntax

Class/stateful component syntax

From the course: React: Using TypeScript (2019)

Start my 1-month free trial

Class/stateful component syntax

- [Narrator] Now that we clearly understand what a class is and how it would be used in programming or React, let's revisit our class component and then add some code to our class. So let's go back to Visuals to do to do code and then open app.tsx and the first thing we're going to do is pass a type to our component. So the way you do this in a component is by using the arrows, so left and right arrow, and then pass the type any or this would work as well. So any would expect anything and this would expect an object type. So what I'm going to do for now, I'm going to do any. And again, as we discussed in the previous video, we are extended the component from React. So this one way to writing the syntax and we could do this this way as well. So we could remove all this and then simply do react.component and this is exactly the same syntax. So I'm going to go back to what I'm used to. Feel free to keep the other syntax if you want to and because we're using class call component, with it…

Contents