Skip to content

Instantly share code, notes, and snippets.

View Lahirutech's full-sized avatar

Lanka Rathanyaka Lahirutech

View GitHub Profile
import { useState } from 'react'
import './App.css'
export default function App() {
const [url, setUrl] = useState("")
const [shurl, setShUrl] = useState("")
// https://api-ssl.bitly.com/v4/shorten
@Lahirutech
Lahirutech / fetchapi.ts
Created March 8, 2024 04:18
Fetch using fetch api
import { useEffect } from 'react'
import './App.css'
export default function App() {
const FetachData = async (uri: string): Promise<any[]> => {
try {
const resp = await fetch(uri)
if (!resp.ok) {
throw new Error(resp.statusText)
@Lahirutech
Lahirutech / FetchApi.tsx
Created March 8, 2024 04:17
fetch Using Axios
import axios from 'axios'
import { useEffect } from 'react'
import './App.css'
// https://jsonplaceholder.typicode.com/posts
export default function App() {
const FetchAPI = async (url: string): Promise<any> => {
try {
const response = await axios.get(url)
import { Document, Model } from "mongoose";
import * as Mongoose from "mongoose";
const postSchema = new Mongoose.Schema({
name: {
type: String,
required: true,
},
});
function searchObjectArray(players, searchString, keys) {
return players.filter(player => {
return keys.some(key => {
return getValueFromKey(player, key).toString().toLowerCase().includes(searchString);
});
});
}
function getValueFromKey(object, key) {
return key.split(".").reduce((o, i) => o[i], object);
import { Roboto } from '@next/font/google';
import { createTheme } from '@mui/material/styles';
import { red } from '@mui/material/colors';
export const roboto = Roboto({
weight: ['300', '400', '500', '700'],
subsets: ['latin'],
display: 'swap',
fallback: ['Helvetica', 'Arial', 'sans-serif'],
});
import * as React from 'react';
import '@/styles/globals.css';
import Head from 'next/head';
import { AppProps } from 'next/app';
import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import { CacheProvider, EmotionCache } from '@emotion/react';
import theme from '../theme';
import createEmotionCache from '../createEmotionCache';
import createCache from '@emotion/cache';
const isBrowser = typeof document !== 'undefined';
// On the client side, Create a meta tag at the top of the <head> and set it as insertionPoint.
// This assures that MUI styles are loaded first.
// It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
export default function createEmotionCache() {
let insertionPoint;
import * as React from 'react';
import Document, { Html, Head, Main, NextScript } from 'next/document';
import createEmotionServer from '@emotion/server/create-instance';
import theme, { roboto } from '../theme';
import createEmotionCache from '../createEmotionCache';
export default class MyDocument extends Document {
render() {
return (
<Html
import React, { useState } from 'react';
function MyComponent() {
const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
// This function is curried and it's a closure because it has access to the setFirstName and setLastName functions
// which are defined in the parent scope
const handleChange = (setter) => (event) => {
setter(event.target.value);
};
return (