Skip to content

Instantly share code, notes, and snippets.

import React from "react";
import { useRouter } from "next/router";
import Link from "next/link";
import { Tab, Tabs } from "react-tabs-scrollable";
import Title from "../Title";
const NavDemo = ({ title }) => {
const [activeTab, setActiveTab] = React.useState(1);
const router = useRouter();
@Mood-al
Mood-al / js
Created May 15, 2022 00:40
react tabs scrollable presist tab state on route changing in next js
import React from "react";
import { useRouter } from "next/router";
import Link from "next/link";
import { Tab, Tabs } from "react-tabs-scrollable";
import Title from "../Title";
const NavDemo = ({ title }) => {
const [activeTab, setActiveTab] = React.useState(1);
const router = useRouter();
@Mood-al
Mood-al / NextNavTabs.js
Last active May 15, 2022 00:45
react tabs scrollable presist tab state on route changing in next js
const NavDemo = () => {
const [activeTab, setActiveTab] = React.useState(1);
const router = useRouter();
// get the id of the page and turn it into integer
const pageId = +router.asPath.split("/")[2];
React.useEffect(() => {
// if it equals 0 set the active tab to 0
if (pageId === 0) {
setActiveTab(0);
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
// this package will help us to get the translations from our API
import Backend from "i18next-http-backend";
// this package will help us to detect the default language of the client browser and set the i18n language to it
import LanguageDetector from "i18next-browser-languagedetector";
import axios from "axios";
import { TRANSLATIONS_BASE_URL } from "./config";
// i18next-http-backend options object that will be passed inside i18next
export const donateRoutes = {
medical_support: {
constant: "sections_medical_support",
sections: [
{
main_section_name: "medical_support",
section_name: "medical-cases",
title_constant_name: "medical_cases_title",
description_constant_name: "medical_cases_description",
route_url: "medical-cases",
@Mood-al
Mood-al / gist:5e0e2cdc23641caf37fed381d6bfb611
Created October 2, 2022 20:12
useInputValueLangaugeDetector.js
import { useEffect, useState } from "react";
import { isRTL } from "../utils/isRTL";
const useInputValueLangaugeDetector = (value, locale) => {
const [dir, setDir] = useState();
const [focussed, setFocussed] = useState(false);
/* If the user is typing and the language is Arabic, then set the direction to
right-to-left. */
import { useEffect, useState } from "react";
import { isRTL } from "../utils/isRTL";
const useInputValueLangaugeDetector = (value, locale) => {
const [dir, setDir] = useState();
const [focussed, setFocussed] = useState(false);
/* If the user is typing and the language is Arabic, then set the direction to
right-to-left. */
import { useEffect, useState } from "react";
import { isRTL } from "../utils/isRTL";
const useInputValueLangaugeDetector = (value, locale) => {
const [dir, setDir] = useState();
const [focussed, setFocussed] = useState(false);
/* If the user is typing and the language is Arabic, then set the direction to
right-to-left. */
@Mood-al
Mood-al / useInputDirectionDetector.js
Last active March 15, 2023 22:49
a react custom hook that detects the direction of an input based on its value
import { useEffect, useState } from "react";
import { isRTL } from "../utils/isRTL";
const useInputDirectionDetector = (value, locale) => {
const [dir, setDir] = useState();
const [focussed, setFocussed] = useState(false);
/* If the user is typing and the language is Arabic, then set the direction to
right-to-left. */
useEffect(() => {
if (value === "" && locale === "ar") {
setDir("rtl");
return;
}
/* The above code is setting the direction of the text to right to left if the user is focussed on
the text box. */
if (focussed) {
isRTL(value) ? setDir("rtl") : setDir("ltr");
}