You’ve probably thought about making reusable components mainly because;
- You hate rewriting code blocks
- You want to work faster
Making a reusable component is pretty simple actually. Assuming you already have a react project created, go ahead and create your Card.js
preferrably in your components directory.
1 | import React from "react"; |
You must have noticed I’m using bootstrap classes, yeah I am. You can install bootstrap as well npm i --save bootstrap
, then don’t forget to add import "bootstrap/dist/css/bootstrap.min.css";
to the very first component, prefferably index.js
So what we did is, we added a few props header, body, footer which are going to be passed down to the next component.
If I go to the App.js component or any other component, I’ll be able to reuse the Card.js by just;
1 | import React from "react"; |
That’s pretty much it.