Skip to content

Commit

Permalink
feat:implements-custom-hook-to-force-component-re-render
Browse files Browse the repository at this point in the history
  • Loading branch information
Enzo707 committed May 22, 2023
1 parent ab0250b commit 24c2603
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import '@hig/fonts/build/ArtifaktElement.css';
import './App.css';
import React, { useEffect, useState } from 'react';
import { useReRender } from './hooks';
import NotificationsPanel from '@dynamods/notifications-panel';
import { EmptyStateArchiver } from './icons';
import Timestamp from '@hig/timestamp';
import axios from 'axios';

function App() {
const [APIData, setAPIData] = useState({ loaded: false, notifications: [], title: 'Notifications', bottomButtonText: 'Mark all as read' });
const [componentIsLoaded, setComponentIsLoaded] = useState(false);
const forceRender = useReRender();

useEffect(() => {
if (process.env.NOTIFICATION_URL) {
Expand Down Expand Up @@ -53,7 +54,7 @@ function App() {
};

const notificationChanged = () => {
setComponentIsLoaded(prevState=> !prevState);
forceRender();
};

const parseNotifications = (notifications) => {
Expand Down
1 change: 1 addition & 0 deletions src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as useReRender } from './use-re-render';
8 changes: 8 additions & 0 deletions src/hooks/use-re-render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useReducer } from 'react';
// This custom hook allow us to force component re-render
const useReRender = () => {
const [, reRender] = useReducer((x) => x + 1, 0);
return reRender;
};

export default useReRender;

0 comments on commit 24c2603

Please sign in to comment.