Skip to content

Instantly share code, notes, and snippets.

View argodeep's full-sized avatar
🌐
Javascript & Product Ethusiasts

Arghyadeep Majumder argodeep

🌐
Javascript & Product Ethusiasts
View GitHub Profile
@argodeep
argodeep / app.tsx
Last active June 26, 2020 14:39
React Functional Component
// Functional compoennt
function App() {
return (
<Fragment>
<Router>
<Switch>
<Route path="/list" exact={true} component={List} />
<Route path="/list/:id" exact={true} component={View} />
<Redirect from="/" to="/list" />
<Route path="*" exact={true} component={List} />
@argodeep
argodeep / app-hook.tsx
Created June 26, 2020 14:49
React Hooks
// Functional component
function Filter(props) {
const [keyword, setKeyword] = useState('');
console.log(props)
// ...
}
// class based component
class Filter extends Component {
constructor(props) {
@argodeep
argodeep / action.tsx
Created June 26, 2020 15:06
Redux Actions
import { GET_CONTACTS, IS_SORTED } from './types';
import { User } from '../../models/user';
export const contactList = (contacts: User[]) => {
return {
type: GET_CONTACTS,
data: contacts
}
}
export const isSorted = (data: boolean) => {
@argodeep
argodeep / api.tsx
Created June 26, 2020 15:21
Redux Reducers
import { ActionModel } from "../../models/action";
export function contacts (state = [], action: ActionModel) {
switch (action.type) {
case "GET_CONTACTS":
return action.data
default:
return state;
}
}
@argodeep
argodeep / lifecylcle.tsx
Created June 26, 2020 15:27
React Hook Lifecycle
useEffect(() => {
console.log('List Mounted')
if (!contacts.length) {
fetchContacts();
}
return function () {
console.log('List Unmounted')
}
}, [])
@argodeep
argodeep / childHandler.tsx
Created June 26, 2020 15:38
React Child to Parent
function handleInput(input: string) {
setKeyword(input)
if (input) {
props.onChange(input);
} else {
props.onChange('')
}
}
@argodeep
argodeep / controlled.tsx
Created June 26, 2020 15:45
React Controlled Component
function handleInput(input: string) {
setKeyword(input)
if (input) {
props.onChange(input);
} else {
props.onChange('')
}
}
<Fragment>
@argodeep
argodeep / axios.tsx
Created June 26, 2020 15:53
React Axios
import axios from "axios";
const API = {
backend: "https://randomuser.me/api/",
};
export const fetchUsers = async () => {
let res = await axios.get(API.backend + '?inc=name,phone&results=20&nat=us');
try {
return res.data.results
@argodeep
argodeep / polyfill.js
Last active May 19, 2025 13:08
Bind, Call, Apply Polyfill using function prototype
let car1 = {
color: 'Red',
company: 'Ferrari',
};
let car2 = {
color: 'Blue',
company: 'BMW',
};
@argodeep
argodeep / recursive.js
Created September 26, 2020 15:47
Breadcrumb using recursive function
const routes = ['home', 'grids', 'grid1'];
const breadcrumbs = [];
let level = 0;
while(level < routes.length) {
breadcrumbs.push(routeTitleLink(routes.slice(0, level+1))); // calling recursive function for each route.
level++
}
console.log(breadcrumbs)