📬 Contact Me:
Github: https://github.com/willshepp28
Email: willsheppard.dev@gmail.com
LinkedIn: https://www.linkedin.com/in/will-sheppard-81a184145/
Github Repo for this project:
https://github.com/willshepp28/Mockedin
Table of Contents
- Introduction
- Why Mockedin-Client?
- Setting Up Mockedin-Client
- Inside Mockedin-Client
- In Layman's Terms
- Conclusion
- Project Folder Structure
Introduction
Welcome, developers! 🎉 Introducing "Mockedin," a client-side project simulating key LinkedIn features. This project is powered by React, Vite, JSON Server, and Concurrently, forming a robust environment for real-world development simulation.
Why Mockedin?
- React: For interactive UI components 🧩
- Vite: For speedy development 🚀
- JSON Server: To mock REST APIs effortlessly 📡
- Concurrently: To run frontend and backend simultaneously, saving development time 🕒
Setting Up Mockedin
With Yarn
- Create new Vite-React project
yarn create vite mockedin-client --template react
- Go into your project folder
cd mockedin-client
- Install JSON Server and Concurrently
yarn add json-server concurrently --dev
- Optionally, install Axios
yarn add axios
- Update package.json scripts
"scripts": {
"dev": "concurrently \"vite\" \"yarn mock-api\"",
"build": "vite build",
"serve": "vite preview",
"mock-api": "json-server --watch db.json --port 5000"
}
- Run your project
yarn dev
With npm
- Create new Vite-React project
npm init vite@latest mockedin-client -- --template react
- Navigate to your project folder
cd mockedin-client
- Install JSON Server and Concurrently
npm install json-server concurrently --save-dev
- Optional: Install Axios
npm install axios
- Update package.json scripts
"scripts": {
"dev": "concurrently \"vite\" \"npm run mock-api\"",
"build": "vite build",
"serve": "vite preview",
"mock-api": "json-server --watch db.json --port 5000"
}
- Run your project
npm run dev
Inside Mockedin-Client
Database File (db.json
)
Create a db.json
file to act as our faux LinkedIn database.
{
"linkedinUsers": [
{ "id": 1, "name": "John Doe", "position": "Developer" },
{ "id": 2, "name": "Jane Smith", "position": "Recruiter" },
{ "id": 3, "name": "Emily Johnson", "position": "CEO" },
{ "id": 4, "name": "Mike Brown", "position": "Sales" }
]
}
React Component (App.jsx
)
Here is how the React component looks to fetch and display data.
import React, { useEffect, useState } from 'react';
import axios from 'axios';
const App = () => {
const [linkedinUsers, setLinkedinUsers] = useState([]);
useEffect(() => {
axios.get('http://localhost:5000/linkedinUsers').then(response => {
setLinkedinUsers(response.data);
});
}, []);
return (
<div>
{linkedinUsers.map(user => (
<div key={user.id}>{user.name} - {user.position}</div>
))}
</div>
);
};
In Layman's Terms
- db.json: A pretend LinkedIn database 📚
- App.jsx: The orchestrator, getting LinkedIn profiles from our mock database and displaying them ðŸŽ
- Concurrently: Our helper that ensures both the stage and the script are set before the show starts 🎬
Conclusion
Mockedin offers a rich development experience with React, Vite, JSON Server, and Concurrently. It is perfect for those wanting to develop LinkedIn-like features without worrying about real-world API limitations. 🌟
Project Folder Structure
Here's how the folder structure of Mockedin-Client looks:
mockedin-client/
├── node_modules/
├── public/
│ └── index.html
├── src/
│ ├── App.jsx
│ └── main.jsx
├── db
.json
├── package.json
└── README.md
Top comments (0)