Skip to content

Instantly share code, notes, and snippets.

View dhanushkac's full-sized avatar
☄️
Expanding my skills

Dhanushka Chandana dhanushkac

☄️
Expanding my skills
View GitHub Profile
@dhanushkac
dhanushkac / InfiniteScrollList.js
Last active January 22, 2023 20:46
Implement an infinite scroll using window height
import React, { useState, useEffect } from 'react';
const InfiniteScrollList = () => {
const [items, setItems] = useState([]);
useEffect(() => {
const loadMore = () => {
// fetch relavant data and update state
}
@dhanushkac
dhanushkac / decimal-pointer-regex.js
Created November 9, 2020 17:17
Decimal pointer separator regex
'10000'.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
// 10,000
const AppContext = React.createContext(defaultValue);
@dhanushkac
dhanushkac / CheckUsername.js
Last active November 9, 2019 13:41
Check username validity by user input
import React, { useState, useEffect } from "react";
import "./styles.css";
function CheckUsername({ url }) {
const [result, setResult] = useState("");
const [data, setData] = useState("");
const handleErrors = response => {
console.log(response);
if (!response.ok) throw Error(response.status);