avoid unnecessary re-renders on user updates

This commit is contained in:
lingdocs 2021-09-18 23:47:46 -04:00
parent c95ab96766
commit ccac58e5eb
3 changed files with 15 additions and 7 deletions

View File

@ -4,7 +4,7 @@
"private": true, "private": true,
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.15.2", "@fortawesome/fontawesome-free": "^5.15.2",
"@lingdocs/lingdocs-main": "^0.1.2", "@lingdocs/lingdocs-main": "^0.1.3",
"@lingdocs/pashto-inflector": "^1.0.5", "@lingdocs/pashto-inflector": "^1.0.5",
"@testing-library/jest-dom": "^4.2.4", "@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2", "@testing-library/react": "^9.3.2",

View File

@ -1,6 +1,10 @@
import React, { createContext, useEffect } from "react" import React, { createContext, useEffect } from "react"
import useStickyState from "./useStickyState"; import useStickyState from "./useStickyState";
import { AT, getUser } from "@lingdocs/lingdocs-main"; import {
AT,
getUser,
userObjIsEqual,
} from "@lingdocs/lingdocs-main";
import { CronJob } from "cron"; import { CronJob } from "cron";
const UserContext = createContext< const UserContext = createContext<
@ -21,7 +25,11 @@ function UserProvider({ children }: any) {
function pullUser() { function pullUser() {
getUser().then((user) => { getUser().then((user) => {
setValue(user === "offline" ? undefined : user); if (user === "offline") return;
// don't update if there's nothing new - to avoid re-renders erasing game input etc
if (!userObjIsEqual(user, value)) {
setValue(user);
}
}).catch(console.error); }).catch(console.error);
} }

View File

@ -1566,10 +1566,10 @@
"@types/yargs" "^15.0.0" "@types/yargs" "^15.0.0"
chalk "^4.0.0" chalk "^4.0.0"
"@lingdocs/lingdocs-main@^0.1.2": "@lingdocs/lingdocs-main@^0.1.3":
version "0.1.2" version "0.1.3"
resolved "https://npm.lingdocs.com/@lingdocs%2flingdocs-main/-/lingdocs-main-0.1.2.tgz#3b56cd272e696c335de4dad1ccff11805970e312" resolved "https://npm.lingdocs.com/@lingdocs%2flingdocs-main/-/lingdocs-main-0.1.3.tgz#631b468eb235aa852395e390925ac118847a4b1c"
integrity sha512-8F3bAahYGZv7qJjVwDxs0IK3k92CuW0aJGJvINipSLFRdd+u5BxvxdiGgYnfocPhHO+rQsOKVskTK1+v5boctA== integrity sha512-AnNDTxqr779POzGbsv/lfGcEFKX+6Q71TUzLY4t/dA8MbsTEp66WGD04gIXSdw7JjojnWA0w9ui/O2nQI6nj5g==
dependencies: dependencies:
nano "^9.0.5" nano "^9.0.5"
passport-github2 "^0.1.12" passport-github2 "^0.1.12"