Skip to content

Instantly share code, notes, and snippets.

View mohxmd's full-sized avatar
:electron:
Never give up

Mohammed mohxmd

:electron:
Never give up
View GitHub Profile
@mohxmd
mohxmd / Signup.jsx
Created July 6, 2023 11:06
React form validation
import { Fragment, useRef, useState } from 'react'
import { Link } from 'react-router-dom'
import styled from 'styled-components'
import { ToastContainer, toast } from 'react-toastify'
import 'react-toastify/dist/ReactToastify.css'
// constants
import { images } from '../../constants'
const SignUp = () => {
@mohxmd
mohxmd / ContextProvider.js
Created June 6, 2023 17:16
global contect provider
import { createContext, useContext, useState, useEffect } from "react"
const StateContext = createContext({
userData: {},
setUserData: () => {},
updateUserData: () => {},
})
export const ContextProvider = ({ children }) => {
const [userData, setUserData] = useState(JSON.parse(localStorage.getItem('user_data')))
@mohxmd
mohxmd / Display.js
Created May 19, 2023 03:06
for react native
import { Dimensions } from "react-native"
const { height, width } = Dimensions.get('window')
const setHeight = h => (height / 100) * h
const setWidth = w => (width / 100) * w
export default { setHeight, setWidth }
@mohxmd
mohxmd / getServerIPAddress.js
Last active May 19, 2023 03:06
current ip address for node js dev
const os = require('os')
function getIPAddress() {
const networkInterfaces = os.networkInterfaces()
let ipAddress = ''
// Iterate over network interfaces
Object.keys(networkInterfaces).forEach(interfaceName => {
const interfaces = networkInterfaces[interfaceName]
// Find the first non-internal and IPv4 address
@mohxmd
mohxmd / Separator.js
Created May 14, 2023 09:48
Separator component for react native
import { View } from 'react-native'
export default function Separator({ height, width, ...extraProps }) {
return (
<View style={{height: height, width: width}} />
)
}
Separator.defaultProps = {
height: 0,
@mohxmd
mohxmd / FocusedStatusBar.js
Created May 14, 2023 09:05
FocusedStatusBar for react native
import { StatusBar } from "react-native"
import { useIsFocused } from "@react-navigation/native"
const FocusedStatusBar = (props) => {
const isFocused = useIsFocused()
return isFocused ? <StatusBar animated={true} {...props} /> : null
}
export default FocusedStatusBar
@mohxmd
mohxmd / useFetch.js
Created May 13, 2023 05:32
useFetch hook for react
import { useState, useEffect } from "react"
import axios from "axios"
const API_KEY = process.env.API_KEY
const useFetch = (endpoint, query) => {
const [date, setData] = useState([])
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState(false)
@mohxmd
mohxmd / theme.js
Created May 13, 2023 03:15
recat-native-constants
const COLORS = {
primary: "#312651",
secondary: "#444262",
tertiary: "#FF7754",
gray: "#83829A",
gray2: "#C1C0C8",
white: "#F3F4F8",
lightWhite: "#FAFAFC",
@mohxmd
mohxmd / date.js
Last active May 13, 2023 02:52
Get Current Date in JavaScript | dd/mm/yyyy Formate Date
let today = new Date()
let day = `${today.getDate() < 10 ? '0' : ''} ${today.getDate()}`
// month are counted from 0
let month = `${(today.getMonth() + 1) < 10 ? '0' : ''} ${today.getMonth()}`
let year = today.getFullYear()
console.log(`Current Date: ${day}/${month}/${year}`);