You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+56Lines changed: 56 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -139,3 +139,59 @@ MongoDB is not vulnerable to SQL injection as it doesn't use SQL queries. Howeve
139
139
- Validate inputs: Use libraries like Joi.
140
140
- Use parameterized queries: Although MongoDB queries are not SQL-based, always treat user input cautiously.
141
141
- Sanitize inputs: Remove any potentially harmful characters or strings.
142
+
### 16. What are React hooks, and how do you create a custom hook?
143
+
React hooks are functions that let you use state and other React features in functional components. A custom hook is a function that starts with use and can call other hooks to encapsulate reusable logic.
144
+
```
145
+
function useFetch(url) {
146
+
const [data, setData] = useState(null);
147
+
useEffect(() => {
148
+
fetch(url)
149
+
.then((response) => response.json())
150
+
.then((data) => setData(data));
151
+
}, [url]);
152
+
return data;
153
+
}
154
+
```
155
+
### 17. How do you handle file uploads in a Node.js application?
156
+
File uploads in a Node.js application can be handled using the multer middleware.
### 18. Explain the virtual DOM and how React uses it to optimize rendering.
166
+
The virtual DOM is a lightweight representation of the actual DOM. React uses it to optimize rendering by comparing the virtual DOM with the actual DOM and updating only the parts that have changed (reconciliation). This minimizes direct manipulation of the actual DOM, leading to better performance.
167
+
### 19. How does the MERN stack handle real-time data?
168
+
Real-time data in a MERN stack application can be handled using WebSockets or libraries like Socket.io. The server (Node.js + Express) sets up a WebSocket connection to communicate with the client (React) in real-time.
169
+
```
170
+
const io = require('socket.io')(server);
171
+
io.on('connection', (socket) => {
172
+
socket.on('message', (data) => {
173
+
io.emit('message', data);
174
+
});
175
+
});
176
+
```
177
+
### 20. How would you implement server-side rendering (SSR) in a MERN stack application?
178
+
Server-side rendering (SSR) in a MERN stack application can be implemented using libraries like Next.js for the React frontend. Next.js handles SSR out of the box and can be integrated with a Node.js/Express backend.
0 commit comments