Skip to content

Instantly share code, notes, and snippets.

@abhimanyuPatil
abhimanyuPatil / Section.tsx
Created September 27, 2022 14:18
Section with children and props
const Section: React.FC<
PropsWithChildren<{
title: string;
}>
> = ({ children, title }) => {
const isDarkMode = useColorScheme() === "dark";
return (
<View style={styles.sectionContainer}>
<Text
style={[
@abhimanyuPatil
abhimanyuPatil / getDataOnMount.ts
Created July 25, 2022 17:29
Fetch Data on mount
import {useEffect, useState} from 'react';
import AxiosConfig from '../services/axiosConfig'; // use your axios config
export function getDataOnMount<T>(endpoint: string, dependency: any[]) {
const [loading, setLoading] = useState(true);
const api = new AxiosConfig();
const [data, setData] = useState<T>();
const [errorMsg,setErr] = useState("")
useEffect(() => {
@abhimanyuPatil
abhimanyuPatil / submitForm.ts
Created July 25, 2022 17:27
Submit Form Hook
import {useState} from 'react';
import AxiosConfig from '../services/axiosConfig'; //use own axios component
export type SubmitFunctionReturn = {
isSuccess: boolean;
data?: any | null;
error?: string | null;
};
export const submitFormHook = () => {
const [loading, setLoading] = useState(false);
const api = new AxiosConfig();
@abhimanyuPatil
abhimanyuPatil / fetchData.ts
Created March 8, 2022 07:04
Custom hook widely used to fetch and set data
export const fetchData = (params:Record<string,string>) => {
const [loading,setLoading] = useState(true)
const [data,setData] = useState([])
const [errorMsg,setErr] = useState("")
useEffect(()=>{
// axios call
axios.get(`/someUrl`)
.then(res=>{
setData(res.data)
setLoading(false)