mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00

* Add application state hook Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de> * Add docs Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
22 lines
850 B
TypeScript
22 lines
850 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { useSelector } from 'react-redux'
|
|
import { ApplicationState } from '../../redux'
|
|
import equal from 'fast-deep-equal'
|
|
|
|
/**
|
|
* Accesses the global application state to retrieve information.
|
|
*
|
|
* @param selector A selector function that extracts the needed information from the state.
|
|
* @param checkForEquality An optional custom equality function. If not provided then {@link equal equal from fast-deep-equal} will be used.
|
|
*/
|
|
export const useApplicationState = <TSelected>(
|
|
selector: (state: ApplicationState) => TSelected,
|
|
checkForEquality?: (a: TSelected, b: TSelected) => boolean
|
|
): TSelected => {
|
|
return useSelector<ApplicationState, TSelected>(selector, checkForEquality ? checkForEquality : equal)
|
|
}
|