react-select-async-paginate
Advanced tools
Comparing version 0.7.8 to 0.7.9
@@ -9,3 +9,3 @@ // src/index.ts | ||
import { useLazyRef } from "@vtaits/use-lazy-ref"; | ||
import { useCallback, useEffect, useRef, useState } from "react"; | ||
import { useCallback, useEffect, useMemo, useRef, useState } from "react"; | ||
import useIsMountedRef from "use-is-mounted-ref"; | ||
@@ -174,3 +174,4 @@ import useLatest from "use-latest"; | ||
reduceOptions = defaultReduceOptions, | ||
shouldLoadMore = defaultShouldLoadMore | ||
shouldLoadMore = defaultShouldLoadMore, | ||
mapOptionsForMenu = void 0 | ||
} = params; | ||
@@ -238,2 +239,8 @@ const menuIsOpenRef = useLatest(menuIsOpen); | ||
const currentOptions = optionsCacheRef.current[inputValue] || getInitialCache(params); | ||
const options = useMemo(() => { | ||
if (!mapOptionsForMenu) { | ||
return currentOptions.options; | ||
} | ||
return mapOptionsForMenu(currentOptions.options); | ||
}, [currentOptions.options, mapOptionsForMenu]); | ||
return { | ||
@@ -245,3 +252,3 @@ handleScrolledToBottom, | ||
isFirstLoad: currentOptions.isFirstLoad, | ||
options: currentOptions.options | ||
options | ||
}; | ||
@@ -307,3 +314,3 @@ }; | ||
// src/useComponents.ts | ||
import { useMemo as useMemo2 } from "react"; | ||
import { useMemo as useMemo3 } from "react"; | ||
import { components as defaultComponents } from "react-select"; | ||
@@ -313,3 +320,3 @@ | ||
import composeRefs from "@seznam/compose-react-refs"; | ||
import { useCallback as useCallback3, useEffect as useEffect2, useMemo, useRef as useRef2 } from "react"; | ||
import { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react"; | ||
import { jsx } from "react/jsx-runtime"; | ||
@@ -338,3 +345,3 @@ var CHECK_TIMEOUT = 300; | ||
}, [shouldHandle, handleScrolledToBottom]); | ||
const setCheckAndHandleTimeout = useMemo(() => { | ||
const setCheckAndHandleTimeout = useMemo2(() => { | ||
const res = () => { | ||
@@ -370,3 +377,3 @@ checkAndHandle(); | ||
); | ||
var useComponents = (components) => useMemo2( | ||
var useComponents = (components) => useMemo3( | ||
() => ({ | ||
@@ -373,0 +380,0 @@ MenuList, |
@@ -56,2 +56,8 @@ import { Ref, ReactElement, ComponentType } from 'react'; | ||
defaultMenuIsOpen?: boolean; | ||
/** | ||
* Post-mapping of loaded options to display them in the menu | ||
* @param options loaded options | ||
* @returns options to display in the menu | ||
*/ | ||
mapOptionsForMenu?: (options: OptionsOrGroups<OptionType, Group>) => OptionsOrGroups<OptionType, Group>; | ||
onInputChange?: (newValue: string, actionMeta: InputActionMeta) => void; | ||
@@ -58,0 +64,0 @@ onMenuClose?: () => void; |
@@ -215,3 +215,4 @@ "use strict"; | ||
reduceOptions = defaultReduceOptions, | ||
shouldLoadMore = defaultShouldLoadMore | ||
shouldLoadMore = defaultShouldLoadMore, | ||
mapOptionsForMenu = void 0 | ||
} = params; | ||
@@ -279,2 +280,8 @@ const menuIsOpenRef = (0, import_use_latest.default)(menuIsOpen); | ||
const currentOptions = optionsCacheRef.current[inputValue] || getInitialCache(params); | ||
const options = (0, import_react.useMemo)(() => { | ||
if (!mapOptionsForMenu) { | ||
return currentOptions.options; | ||
} | ||
return mapOptionsForMenu(currentOptions.options); | ||
}, [currentOptions.options, mapOptionsForMenu]); | ||
return { | ||
@@ -286,3 +293,3 @@ handleScrolledToBottom, | ||
isFirstLoad: currentOptions.isFirstLoad, | ||
options: currentOptions.options | ||
options | ||
}; | ||
@@ -289,0 +296,0 @@ }; |
{ | ||
"name": "react-select-async-paginate", | ||
"version": "0.7.8", | ||
"version": "0.7.9", | ||
"description": "Wrapper above react-select that supports pagination on menu scroll", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -23,2 +23,3 @@ [![NPM](https://img.shields.io/npm/v/react-select-async-paginate.svg)](https://www.npmjs.com/package/react-select-async-paginate) | ||
- [Manual control of input value and menu opening](https://codesandbox.io/s/6y34j51k1n) | ||
- [Show selected items on top of the menu](https://codesandbox.io/p/sandbox/gpdkwk) | ||
- [react-hook-form integration](https://codesandbox.io/s/x7vw8c) | ||
@@ -121,2 +122,6 @@ | ||
### mapOptionsForMenu | ||
Not required. Function. Post-mapping of loaded options to display them in the menu. Can be used to put selected options to top of the list. | ||
### selectRef | ||
@@ -123,0 +128,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
115639
1036
369