From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Accessing props

Accessing props

Welcome back, let's discuss how we can access props in our components. In function components, we can receive the props as an object. All the attributes that are defined as part of the object will be available in the component. Whereas, in the class component, the props object already contains whatever props has been passed on to the component. Let's do a quick example of the greeting functional component props. I'll open our project in VS Code. Let's have a component, greetings.tsx, let's do rafce and our component has been available. Now over here, I'm going to receive some props. We decide what props do we need while we start the development of our component. In this example, I'm going to receive a name and age. Now over here in this div, we are going to use these values. We'll say greetings to the name. You are age years old. Now it's complaining us in the typescript that it does not have a data type defined. For now, we are going to keep it as any. So, for this whole object, we…

Contents