From 974a3d3e4f16f8d7bb49d85f97714928dfff22e2 Mon Sep 17 00:00:00 2001 From: "Vytautas A." Date: Wed, 11 Dec 2024 22:14:56 -0600 Subject: [PATCH] Fix warnings --- .eslintrc.js | 8 -------- src/App.js | 6 +++--- src/components/EditOffer.js | 5 ++--- src/components/EditProperty.js | 5 ++--- src/components/Login.js | 1 - src/components/Register.js | 1 - src/components/SubmitOffer.js | 4 ++-- src/containers/AdminDashboard.js | 8 ++++---- src/containers/CustomerDashboard.js | 2 +- src/containers/Footer/Footer.js | 5 +---- src/context/UserContextProvider.js | 11 ++++++----- 11 files changed, 21 insertions(+), 35 deletions(-) delete mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index dbd7dd3..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - rules: { - "no-unused-vars": "off", - "no-console": "off", - "react-hooks/rules-of-hooks": "off", - // Add other rules you want to disable here - }, -}; \ No newline at end of file diff --git a/src/App.js b/src/App.js index c44a0b9..9240389 100644 --- a/src/App.js +++ b/src/App.js @@ -2,12 +2,12 @@ import './App.css'; import { BrowserRouter } from "react-router-dom"; import Header from "./containers/Header/Header"; import PageRoutes from './routes/PageRoutes'; -import { useContext, useEffect } from 'react'; +import {useContext, useEffect} from 'react'; import UserContext from "./context/UserContext"; import Footer from "./containers/Footer/Footer"; -const App = () => { +const App = (callback, deps) => { const { currentUser, updateUser } = useContext(UserContext) document.title = 'NextHome | #1 Real Estate Platform in the World!'; @@ -22,7 +22,7 @@ const App = () => { updateUser(JSON.parse(user)); } - }, []); + }, [updateUser]); return ( diff --git a/src/components/EditOffer.js b/src/components/EditOffer.js index 196ca90..012f6a4 100644 --- a/src/components/EditOffer.js +++ b/src/components/EditOffer.js @@ -1,7 +1,6 @@ -import React, {useEffect, useRef, useState} from "react"; -import {Link, useLocation, useNavigate, useParams} from "react-router-dom"; +import React, {useRef} from "react"; +import {useLocation, useNavigate} from "react-router-dom"; import FetchService from "../service/FetchService"; -import hasRole from "../util/hasRole"; const EditProperty = ({ currentUser }) => { diff --git a/src/components/EditProperty.js b/src/components/EditProperty.js index 0b8bf47..65c1b1f 100644 --- a/src/components/EditProperty.js +++ b/src/components/EditProperty.js @@ -1,7 +1,6 @@ -import React, { useEffect, useRef, useState } from "react"; -import { Link, useLocation, useNavigate, useParams } from "react-router-dom"; +import React, { useRef } from "react"; +import { useLocation, useNavigate, useParams } from "react-router-dom"; import FetchService from "../service/FetchService"; -import hasRole from "../util/hasRole"; const EditProperty = ({ currentUser }) => { diff --git a/src/components/Login.js b/src/components/Login.js index 728cc60..9869a57 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -2,7 +2,6 @@ import React, { useRef } from "react"; import { useNavigate } from "react-router-dom"; import FetchService from "../service/FetchService"; import extractJwtPayload from "../util/extractJwtPayload"; -import pageRoutes from "../routes/PageRoutes"; const Login = ({ setCurrentUser }) => { diff --git a/src/components/Register.js b/src/components/Register.js index 29872c8..68002a2 100644 --- a/src/components/Register.js +++ b/src/components/Register.js @@ -1,6 +1,5 @@ import React, { useRef } from "react"; import FetchService from "../service/FetchService"; -import extractJwtPayload from "../util/extractJwtPayload"; import { useNavigate } from "react-router-dom"; function Register() { diff --git a/src/components/SubmitOffer.js b/src/components/SubmitOffer.js index 75e727a..1f850ee 100644 --- a/src/components/SubmitOffer.js +++ b/src/components/SubmitOffer.js @@ -1,5 +1,5 @@ -import React, { useContext, useEffect, useRef, useState } from "react"; -import { Link, useParams } from "react-router-dom"; +import React, { useContext, useRef } from "react"; +import { Link } from "react-router-dom"; import FetchService from "../service/FetchService"; import hasRole from "../util/hasRole"; import UserContext from "../context/UserContext"; diff --git a/src/containers/AdminDashboard.js b/src/containers/AdminDashboard.js index f127bdd..7cc9e28 100644 --- a/src/containers/AdminDashboard.js +++ b/src/containers/AdminDashboard.js @@ -1,4 +1,4 @@ -import React, { useEffect } from "react"; +import React, {useCallback, useEffect} from "react"; import FetchService from "../service/FetchService"; function AdminDashboard({ currentUser }) { @@ -6,13 +6,13 @@ function AdminDashboard({ currentUser }) { const [ownersState, setOwnersState] = React.useState([]); - const refreshOwners = () => { + const refreshOwners = useCallback(() => { FetchService.getPendingOwners(currentUser.accessToken).then((response) => setOwnersState(response.data) ); - }; + }, [currentUser.accessToken]); - useEffect(() => refreshOwners(), []); + useEffect(() => refreshOwners(), [refreshOwners]); const approveOwner = (userId) => { FetchService.approveOwner(currentUser.accessToken, userId).then(() => diff --git a/src/containers/CustomerDashboard.js b/src/containers/CustomerDashboard.js index b088576..e315e04 100644 --- a/src/containers/CustomerDashboard.js +++ b/src/containers/CustomerDashboard.js @@ -1,7 +1,7 @@ import React, {useCallback, useEffect} from "react"; import FetchService from "../service/FetchService"; import formatMoney from "../util/formatMoney"; -import { Link, Navigate } from "react-router-dom"; +import { Link } from "react-router-dom"; function CustomerDashboard({ currentUser }) { const [offersState, setOffersState] = React.useState([]); diff --git a/src/containers/Footer/Footer.js b/src/containers/Footer/Footer.js index 8c9b55f..156c322 100644 --- a/src/containers/Footer/Footer.js +++ b/src/containers/Footer/Footer.js @@ -1,7 +1,4 @@ -import React, { useContext } from "react"; -import { Link, useNavigate } from "react-router-dom"; -import UserContext from "../../context/UserContext"; -import hasRole from "../../util/hasRole"; +import React from "react"; import './Footer.css'; const Footer = () => { diff --git a/src/context/UserContextProvider.js b/src/context/UserContextProvider.js index f9bbeec..c0ffec0 100644 --- a/src/context/UserContextProvider.js +++ b/src/context/UserContextProvider.js @@ -1,12 +1,13 @@ -import { useState } from "react"; +import {useCallback, useState} from "react"; import UserContext from "./UserContext"; const UserContextProvider = ({ children }) => { - const [currentUser, setcurrentUser] = useState(null); + const [currentUser, setCurrentUser] = useState(null); - const updateUser = (newUser) => { - setcurrentUser(newUser); - }; + // Memoize the updateUser function + const updateUser = useCallback((newUser) => { + setCurrentUser(newUser); + }, []); return (