Skip to content

Commit 9141255

Browse files
authored
fix: select only the required values from state and useEffect to get description error message (#3395)
* Update dependencies and workspace * Select only the required values from the state Having the selector returning the entire state and then using spread operators to get the values we want will cause components to rerender. This will impact performance because if a component has the entire state and a part of the state it does not use is updated, the component has to rerender. To avoid this, only get what you need from the state for a component. * Ensure that AutoComplete finishes rendering before calling ValidationProvider ValidationProvider is updating when AutoComplete tries to call it while rendering.
1 parent b99029e commit 9141255

File tree

25 files changed

+105
-58
lines changed

25 files changed

+105
-58
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@
2222
"*.tsx": "$(capture).ts, $(capture).d.ts, $(capture).spec.tsx, $(capture).styles.ts",
2323
"package.json": "package-lock.json, .npmrc"
2424
},
25+
"cSpell.words": [
26+
"fluentui"
27+
],
2528
}

package-lock.json

Lines changed: 22 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"eslint-config-react-app": "7.0.1",
3434
"eslint-plugin-react": "7.33.2",
3535
"eslint-webpack-plugin": "4.1.0",
36-
"express": "4.21.0",
36+
"express": "^4.21.1",
3737
"expvariantassignmentsdk": "file:packages/expvariantassignmentsdk-1.0.0.tgz",
3838
"file-loader": "6.2.0",
3939
"fork-ts-checker-webpack-plugin": "9.0.2",

src/app/services/context/validation-context/ValidationProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface ValidationProviderProps {
1313
}
1414

1515
export const ValidationProvider = ({ children }: ValidationProviderProps) => {
16-
const { resources } = useAppSelector((state) => state);
16+
const resources = useAppSelector((state) => state.resources);
1717
const base = Object.keys(resources.data).length > 0 ?
1818
resources.data[GRAPH_API_VERSIONS[0]].children! : [];
1919

src/app/views/app-sections/StatusMessages.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import MessageDisplay from '../common/message-display/MessageDisplay';
99

1010
const StatusMessages = () => {
1111
const dispatch = useAppDispatch();
12-
const { queryRunnerStatus, sampleQuery } =
13-
useAppSelector((state) => state);
12+
const queryRunnerStatus = useAppSelector((state)=> state.queryRunnerStatus);
13+
const sampleQuery = useAppSelector((state)=> state.sampleQuery);
1414

1515
function setQuery(link: string) {
1616
const query: IQuery = { ...sampleQuery };

src/app/views/app-sections/TermsOfUseMessage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import { appStyles } from '../App.styles';
99

1010
const StyledTermsOfUseMessage = () => {
1111

12-
const { termsOfUse } =
13-
useAppSelector((state) => state);
12+
const termsOfUse = useAppSelector((state) => state.termsOfUse);
1413

1514
const dispatch = useAppDispatch();
1615
if (termsOfUse) {

src/app/views/authentication/Authentication.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { translateMessage } from '../../utils/translate-messages';
1616
const Authentication = (props: any) => {
1717
const dispatch: AppDispatch = useAppDispatch();
1818
const [loginInProgress, setLoginInProgress] = useState(false);
19-
const { auth: { authToken } } = useAppSelector((state) => state);
19+
const authToken = useAppSelector((state) => state.auth.authToken);
2020
const tokenPresent = !!authToken.token;
2121
const logoutInProgress = !!authToken.pending;
2222

src/app/views/main-header/FeedbackButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { useAppSelector } from '../../../store';
88

99
export const FeedbackButton = () => {
1010
const [enableSurvey, setEnableSurvey] = useState(false);
11-
const { profile: { user } } = useAppSelector((state) => state);
11+
const user = useAppSelector((state) => state.profile.user)
12+
1213
const currentTheme = getTheme();
1314
const feedbackIcon : IIconProps = {
1415
iconName : 'Feedback'

src/app/views/main-header/Help.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { mainHeaderStyles } from './MainHeader.styles';
1717
import { useAppSelector } from '../../../store';
1818

1919
export const Help = () => {
20-
const { auth: { authToken } } = useAppSelector((state) => state);
20+
const auth = useAppSelector((state)=> state.auth)
21+
const authToken = auth.authToken;
2122
const authenticated = authToken.token;
2223
const [items, setItems] = useState([]);
2324
const currentTheme = getTheme();

src/app/views/main-header/MainHeader.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ registerIcons({
2929
}
3030
});
3131
export const MainHeader: React.FunctionComponent<MainHeaderProps> = (props: MainHeaderProps) => {
32-
const { profile: { user }, graphExplorerMode, sidebarProperties } = useAppSelector(
33-
(state) => state
34-
);
32+
const profile = useAppSelector((state)=> state.profile)
33+
const user = profile.user;
34+
const graphExplorerMode = useAppSelector((state)=> state.graphExplorerMode)
35+
const sidebarProperties = useAppSelector((state)=> state.sidebarProperties)
3536

3637
const mobileScreen = !!sidebarProperties.mobileScreen;
3738
const showSidebar = !!sidebarProperties.showSidebar;

0 commit comments

Comments
 (0)