-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added all sample explorations related to common states, hoc components
- Loading branch information
1 parent
8fc087c
commit cf397d3
Showing
15 changed files
with
707 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React, { useLayoutEffect } from "react"; | ||
import withNavigator from "./withNavigator"; | ||
import { useAuthState } from "../state/useAuthState"; | ||
|
||
const withAuth = (WrappedComponent) => { | ||
const { data } = useAuthState(); | ||
return (props) => { | ||
useLayoutEffect(() => { | ||
if (data?.isSignedIn) { | ||
console.log("user is signed in"); | ||
} else { | ||
console.log("user is not signedin"); | ||
} | ||
return () => { | ||
console.log("Component unmounted"); | ||
}; | ||
}, []); | ||
const WrappedComp = withNavigator(WrappedComponent); | ||
return <WrappedComp {...props} />; | ||
}; | ||
}; | ||
|
||
export default withAuth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { useLayoutEffect } from "react"; | ||
import { useNavigatorState } from "../state/useNavigatorState"; | ||
|
||
const withNavigator = (WrappedComponent) => { | ||
const { setData, data } = useNavigatorState(); | ||
|
||
return (props) => { | ||
useLayoutEffect(() => { | ||
data?.currentScreen != window.location.pathname && | ||
setData({ | ||
...data, | ||
currentScreen: window.location.pathname, | ||
history: data?.history | ||
? [...data?.history, window.location.pathname] | ||
: [window.location.pathname], | ||
previousScreen: data?.currentScreen, | ||
}); | ||
|
||
return () => { | ||
console.log("Component unmounted withNavigator"); | ||
}; | ||
}, []); | ||
|
||
return <WrappedComponent {...props} />; | ||
}; | ||
}; | ||
|
||
export default withNavigator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App.jsx' | ||
import './index.css' | ||
import { I18nextProvider } from 'react-i18next'; | ||
import i18n from './configs/i18.js'; | ||
import React from "react"; | ||
import ReactDOM from "react-dom/client"; | ||
import App from "./App.jsx"; | ||
import "./index.css"; | ||
import { I18nextProvider } from "react-i18next"; | ||
import i18n from "./configs/i18.js"; | ||
import { QueryClientProvider } from "@tanstack/react-query"; | ||
import { hydrateAllQueries, queryClient } from "./state/stateConfigs"; | ||
|
||
const initializeApp = async () => { | ||
await hydrateAllQueries(); | ||
ReactDOM.createRoot(document.getElementById("root")).render( | ||
<React.StrictMode> | ||
<QueryClientProvider client={queryClient}> | ||
<I18nextProvider i18n={i18n}> | ||
<App /> | ||
</I18nextProvider> | ||
</QueryClientProvider> | ||
</React.StrictMode> | ||
); | ||
}; | ||
|
||
|
||
|
||
ReactDOM.createRoot(document.getElementById('root')).render( | ||
<React.StrictMode> | ||
<I18nextProvider i18n={i18n}> | ||
<App /> | ||
</I18nextProvider> | ||
</React.StrictMode>, | ||
) | ||
initializeApp(); |
Oops, something went wrong.