lodash APIs
- cloneDeep
- get
- isEqual
- isEmpty
- debounce
- merge
- uniq
- omit
- isString
- isArray
- pick
- sortBy
- groupBy
- flatten
- set
- find
- orderBy
- mapValues
- isObject
- last
- isNil
- isNumber
- range
- chunk
- throttle
- filter
- uniqBy
- difference
- pickBy
- noop
- capitalize
- uniqueId
- has
- isUndefined
- map
- camelCase
- isFunction
- kebabCase
- intersection
- random
- includes
- isPlainObject
- compact
- Dictionary
- findIndex
- keyBy
- forEach
- trim
- clamp
- identity
- remove
- keys
- isNull
- times
- startCase
- first
- values
- mapKeys
- sumBy
- max
- reduce
- some
- zip
- every
- memoize
- clone
- countBy
- concat
- snakeCase
- assign
- isBoolean
- uniqWith
- omitBy
- without
- minBy
- head
- maxBy
- min
- upperFirst
- escapeRegExp
- reverse
- sample
- shuffle
- defaults
- inRange
- flattenDeep
- take
- union
- sum
- mergeWith
- castArray
- replace
- flatMap
- reject
- zipObject
- template
- isNaN
- mean
- size
- findLast
- unset
- partition
- round
- fromPairs
- floor
- toPairs
- indexOf
- toString
- sampleSize
- differenceBy
- update
- chain
- startsWith
- xor
- pull
- DebouncedFunc
- defaultsDeep
- split
- findKey
- unescape
- partial
- toNumber
- invert
- each
- differenceWith
- endsWith
- slice
- isDate
- unionBy
- findLastIndex
- join
- isInteger
- delay
- isObjectLike
- padStart
- result
- isError
- extend
- cloneDeepWith
- upperCase
- trimStart
- constant
- matches
- lowerCase
- forIn
- lowerFirst
- once
- transform
- isMatch
- escape
- isEqualWith
- zipWith
- isRegExp
- entries
- sortedIndexBy
- dropWhile
- takeWhile
- isElement
- forEachRight
- ReplaceFunction
- TemplateExecutor
- keysIn
- IsEqualCustomizer
- isTypedArray
- cond
- stubTrue
- toUpper
- isMap
- isSet
- meanBy
- rangeRight
- repeat
- trimEnd
- now
- nth
- pullAt
- toPath
- eq
- lt
- lte
- gt
- gte
- pullAllBy
- pullAll
- toLower
- fill
- ceil
- flatMapDeep
- CloneDeepWithCustomizer
- negate
- takeRightWhile
- invoke
- tap
- intersectionWith
- truncate
- Collection
- bind
- curry
- partialRight
- sortedUniq
- sortedIndexOf
- Object
- drop
- _
Other Related APIs
lodash#nth TypeScript Examples
The following examples show how to use
lodash#nth.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: createTableHook.ts From advocacy-maps with MIT License | 4 votes |
export function createTableHook<Item, Refinement, PageKey>({
name,
getPageKey,
getItems
}: Config<Item, Refinement, PageKey>) {
function reducer(
state: State<Refinement, PageKey>,
action: Action<Item, Refinement>
): State<Refinement, PageKey> {
if (action.type === "nextPage" || action.type === "previousPage") {
const next = state.currentPage + (action.type === "nextPage" ? 1 : -1)
if (next >= 0 && next < state.pageKeys.length) {
return {
...state,
currentPage: next,
currentPageKey: state.pageKeys[next],
...adjacentKeys(state.pageKeys, next)
}
} else {
return state
}
} else if (action.type === "onSuccess") {
const keys = [...state.pageKeys]
const item = nth(action.page, state.itemsPerPage - 1)
if (item !== undefined)
keys[state.currentPage + 1] = getPageKey(item, state.refinement)
return {
...state,
pageKeys: keys,
...adjacentKeys(keys, state.currentPage)
}
} else if (action.type === "error") {
console.warn(`Error in ${name} table hook`, action.error)
return { ...state, error: action.error }
} else if (action.type === "refine") {
return {
...state,
refinement: { ...state.refinement, ...action.refinement },
...initialPage
}
}
return state
}
return (initialRefinement: Refinement) => {
const [
{
refinement,
itemsPerPage,
currentPageKey,
currentPage,
nextKey,
previousKey
},
dispatch
] = useReducer(reducer, {
...initialPage,
itemsPerPage: 10,
refinement: initialRefinement,
error: null
})
const items = useAsync(
() => {
return getItems(refinement, itemsPerPage, currentPageKey)
},
[currentPageKey, refinement, itemsPerPage],
{
onSuccess: page => dispatch({ type: "onSuccess", page }),
onError: error => dispatch({ type: "error", error })
}
)
const pagination = useMemo(
() => ({
itemsPerPage,
currentPage: currentPage + 1,
nextPage: () => dispatch({ type: "nextPage" }),
previousPage: () => dispatch({ type: "previousPage" }),
hasNextPage: nextKey !== undefined,
hasPreviousPage: previousKey !== undefined
}),
[currentPage, itemsPerPage, nextKey, previousKey]
)
return useMemo(
() => ({
pagination,
items,
refinement,
refine: (refinement: Refinement) =>
dispatch({ type: "refine", refinement })
}),
[pagination, items, refinement]
)
}
}