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
import React, { InputHTMLAttributes, useEffect, useRef } from 'react'; | |
// Persian/Arabic To English Number | |
const f2e = (event) => { | |
event.target.value = event.target.value | |
.replace(/[٠-٩]/g, (d) => '٠١٢٣٤٥٦٧٨٩'.indexOf(d)) | |
.replace(/[۰-۹]/g, (d) => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d)); | |
return event; | |
}; |
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
import React from 'react'; | |
import Link from 'next/link'; | |
export default function HomePage() { | |
return ( | |
<div> | |
<h2>Hello World!</h2> | |
<Link href="/dashboard">Go to Dashboard</Link> | |
</div> | |
); |
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
import React from 'react'; | |
import withPrivateRoute from '../components/withPrivateRoute'; | |
const Dashboard = () => { | |
return <div>This is a Dashboard page which is private.</div>; | |
}; | |
Dashboard.getInitialProps = async props => { | |
console.info('##### Congratulations! You are authorized! ######', props); | |
return {}; |
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
import React from 'react'; | |
import Router from 'next/router'; | |
const login = '/login?redirected=true'; // Define your login route address. | |
/** | |
* Check user authentication and authorization | |
* It depends on you and your auth service provider. | |
* @returns {{auth: null}} | |
*/ |
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
const [installationStatus, installationEvent] = useInstallPrompt(true); | |
useEffect(() => { | |
// installationStatus is one of these states: null/dismissed/accepted/installed | |
if(installationStatus === 'accepted') { | |
// User accept it. You can save it in some log with device config. | |
} | |
// Show Add-to-home-screen prompt, if user have it's condition. | |
if(installationEvent) { |
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
const isOnline = useNetwork(); // true/false |
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
const isVisible = useVisibility(); // true/false |
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
const isPwa = usePwa(); // true/false |
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
useEffect(() => { | |
console.log(Device()); | |
}) | |
// { | |
// "browser": { | |
// "name": "Safari", | |
// "version": "11.0" | |
// }, | |
// "os": { |
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
// npm install react-pwa-toolkit | |
import React from "react"; | |
import Device, { useNetwork, usePwa, useVisibility, useInstallPrompt } from "react-pwa-toolkit"; |
NewerOlder