Skip to content

Commit

Permalink
Used per package imports for lodash
Browse files Browse the repository at this point in the history
Per https://lodash.com/per-method-packages

 if you import or require methods directly, e.g. const throttle = require('lodash/throttle'), only the subset of lodash code your package uses will be bundled in projects that use your package.

fnando/i18n#41 also has done it and had a
measurable decrease
  • Loading branch information
trajano committed Dec 23, 2022
1 parent c98ca10 commit c08f3a7
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"react": "18",
"react-dom": "18",
"react-scripts": "^5.0.1",
"typedoc": "^0.23.22",
"typedoc": "^0.23.23",
"typescript": "^4.9.4"
},
"eslintConfig": {
Expand Down
2 changes: 1 addition & 1 deletion src/debounce.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debounce } from "lodash";
import { debounce } from "lodash/debounce";
describe("debounce", () => {
beforeEach(() => {
jest.useFakeTimers("modern");
Expand Down
2 changes: 1 addition & 1 deletion src/usePolling/usePollingIfError.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment jsdom
*/
import { render, waitFor } from '@testing-library/react';
import { noop } from 'lodash';
import noop from 'lodash/noop';
import React from 'react';
import { usePollingIf } from './usePollingIf';

Expand Down
2 changes: 1 addition & 1 deletion src/useStates/useDebouncedDeepState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debounce } from "lodash";
import debounce from "lodash/debounce";
import { Dispatch, useCallback, useEffect } from "react";
import { useDeepState } from "./useDeepState";

Expand Down
2 changes: 1 addition & 1 deletion src/useStates/useDebouncedState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debounce } from "lodash";
import debounce from "lodash/debounce";
import { Dispatch, useCallback, useEffect, useState } from "react";

/**
Expand Down
4 changes: 2 additions & 2 deletions src/useStates/useDeepState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEqual } from "lodash";
import isEqual from "lodash/isequal";
import { Dispatch, useReducer } from "react";

/**
Expand All @@ -12,7 +12,7 @@ import { Dispatch, useReducer } from "react";
export function useDeepState<S>(initialState: S | (() => S)): [S, Dispatch<S>] {
const initialStateIsFunction = typeof initialState === "function";
return useReducer(
(state: S, newState: S) => isEqual(state, newState) ? state : newState,
(state: S, newState: S) => (isEqual(state, newState) ? state : newState),
initialStateIsFunction ? (null as unknown as S) : initialState,
initialStateIsFunction
? (initialState as () => S)
Expand Down

0 comments on commit c08f3a7

Please sign in to comment.