Skip to content

Instantly share code, notes, and snippets.

@night-fury-rider
night-fury-rider / react-export-individually.ts
Created January 14, 2024 08:55
React - Export Individually
export const getTotal = ()=>{}
export const saveData = ()=>{}
@night-fury-rider
night-fury-rider / jest-mocking-partial-mock-own-methods.test.tsx
Last active December 28, 2023 08:21
Jest - Partially Mocking Own Methods
jest.mock("$dashboard/ContactService", ()=> {
const actualModule = jest.requireActual("../dashboard/ContactService");
return {
__esModule: true,
...actualModule,
size: 100,
deleteContact: jest.fn()
}
open: jest.fn()
});
@night-fury-rider
night-fury-rider / jest-mocking-library-methods.test.tsx
Last active December 27, 2023 06:02
Jest - Mocking Library Methods
jest.mock("react-native-share", ()=> {
open: jest.fn()
});
@night-fury-rider
night-fury-rider / use-memo.tsx
Last active March 23, 2021 07:13
React - Hook useMemo
import React, { useMemo } from 'react';
function App() {
const arr = [1, 2, 33, 4];
// Memorize output as long as dependency array elements are not changed.
const memiozedValue = useMemo(() => getLargestValue(), [arr]);
function getLargestValue() {
return Math.max(...arr);
const routes = [
{
path: "/sandwiches",
component: Sandwiches
},
{
path: "/tacos",
component: Tacos,
routes: [
{
@night-fury-rider
night-fury-rider / context-api.tsx
Created March 23, 2021 06:54
React - Context API
import React from 'react';
const UserContext = React.createContext('Yuvraj');
const UserProvider = UserContext.Provider;
const UserConsumer = UserContext.Consumer;
function UVHeader() {
return (
<UserConsumer>
@night-fury-rider
night-fury-rider / react-hoc.tsx
Last active March 23, 2021 04:06
React - Higher Order Component (HOC)
import React from 'react';
function SuccessButton (props: any) {
return (
<div style={{color: "green"}}>SuccessButton ----------------- {props.data}</div>
);
}
function WarningButton (props: any) {
return (
@night-fury-rider
night-fury-rider / use-selector.tsx
Last active March 23, 2021 04:10
React Hook - useSelector
import React from 'react';
import UVNumber from '../../components/uv_number/uv_number';
import { useSelector } from 'react-redux';
import { UVRootState } from '../../root.reducer';
function UVDashboard() {
let uvNumberData = useSelector((state: UVRootState) => {
return state.dashboard.numbers;
@night-fury-rider
night-fury-rider / react-axios-api.ts
Created March 15, 2021 03:06
React API call using Axios
import axios from 'axios';
const getDashboardData = ()=> {
return axios.get('https://demo1926272.mockable.io/getInvestments');
}
const UVDashboardApi = {
getDashboardData: getDashboardData
};
@night-fury-rider
night-fury-rider / react-memo.tsx
Last active January 24, 2024 05:08
React memo
import React, { memo } from 'react';
function UVNumber(props: any) {
return (
<div> Memo by Yuvraj Patil</div>
)
}
export default memo(UVNumber);