Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part 3: Refactor App.js to use <Routes> instead of <Switch> #183

Open
wants to merge 12 commits into
base: PART_3
Choose a base branch
from
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: adrianhajdin
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ Using React, Node.js, Express & MongoDB you'll learn how to build a Full Stack M

By the end of this video, you will have a strong understanding of how the MERN Stack works.

### [🌟 Become a top 1% Next.js 13 developer in only one course](https://jsmastery.pro/next13)
### [🚀 Land your dream programming job in 6 months](https://jsmastery.pro/masterclass)

Setup:
- run ```npm i && npm start``` for both client and server side to start the app
- run ```npm i && npm start``` for both client and server side to start the app
16,521 changes: 10,065 additions & 6,456 deletions client/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Container } from '@material-ui/core';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import { BrowserRouter, Routes, Route } from "react-router-dom";

import Home from './components/Home/Home';
import Navbar from './components/Navbar/Navbar';
Expand All @@ -10,10 +10,10 @@ const App = () => (
<BrowserRouter>
<Container maxWidth="lg">
<Navbar />
<Switch>
<Routes>
<Route path="/" exact component={Home} />
<Route path="/auth" exact component={Auth} />
</Switch>
</Routes>
</Container>
</BrowserRouter>
);
Expand Down
2 changes: 1 addition & 1 deletion client/src/actions/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const likePost = (id) => async (dispatch) => {

export const deletePost = (id) => async (dispatch) => {
try {
await await api.deletePost(id);
await api.deletePost(id);

dispatch({ type: DELETE, payload: id });
} catch (error) {
Expand Down
7 changes: 3 additions & 4 deletions client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';

// Install "npm install @reduxjs/toolkit" on server side
import { configureStore } from "@reduxjs/toolkit";
import { reducers } from './reducers';
import App from './App';
import './index.css';

const store = createStore(reducers, compose(applyMiddleware(thunk)));
const store = configureStore({ reducer: reducers });

ReactDOM.render(
<Provider store={store}>
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const deletePost = async (req, res) => {

if (!mongoose.Types.ObjectId.isValid(id)) return res.status(404).send(`No post with id: ${id}`);

await PostMessage.findByIdAndRemove(id);

await PostMessage.findByIdAndDelete(id);
res.json({ message: "Post deleted successfully." });
}

Expand Down
Loading