Passing Object props into React TypeScript Component using Nx
Published in
2 min readJul 25, 2023
Prerequisites
- Make sure you have installed Node.js version 16+.
- To follow along with this article, you’ll need a react project that is generated with Nx. If you haven’t done it yet, see this article.
You can still follow the article by creating components in your own way.
Create Person Component
For demonstration, let’s create a Person component. Run the following command.
nx g c person --dir app/components
Open person.tsx and write the following code in it.
We defined PersonModel as a type and used it in PersonProps. And then call this component in the App Component.
Call from App Component
Open app.tsx and write the following code.
You can see that we declared a person object and passed it into the Person component.
Serve the Application
Run with nx serve
and see the result.
Done
This is how we can pass objects into a react typescript component.