mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-25 22:44:19 +00:00
📔 Document useBackendViewset
This commit is contained in:
parent
b37eda411f
commit
fdb3e64dad
1 changed files with 10 additions and 5 deletions
|
@ -4,7 +4,14 @@ import ContextUser from "../contexts/ContextUser"
|
||||||
import makeURLSearchParams from "../utils/makeURLSearchParams"
|
import makeURLSearchParams from "../utils/makeURLSearchParams"
|
||||||
|
|
||||||
|
|
||||||
export default function useBackendViewset(resourcesPath, pkName) {
|
/**
|
||||||
|
* An hook which allows access to a full REST viewset (list, create, retrieve, edit, delete).
|
||||||
|
*
|
||||||
|
* @param resourcesPath - The path of the resource directory.
|
||||||
|
* @param pkName - The name of the primary key attribute of the elements.
|
||||||
|
* @param refreshOnStart - Whether the data should be loaded at the first startup (defaults to true).
|
||||||
|
*/
|
||||||
|
export default function useBackendViewset(resourcesPath, pkName, refreshOnStart = true) {
|
||||||
const { server } = useContext(ContextServer)
|
const { server } = useContext(ContextServer)
|
||||||
const configured = server !== null
|
const configured = server !== null
|
||||||
|
|
||||||
|
@ -195,14 +202,12 @@ export default function useBackendViewset(resourcesPath, pkName) {
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => {
|
() => {
|
||||||
if(!(
|
if(refreshOnStart && !(loaded || running)) {
|
||||||
loaded || running
|
|
||||||
)) {
|
|
||||||
// noinspection JSIgnoredPromiseFromCall
|
// noinspection JSIgnoredPromiseFromCall
|
||||||
refreshResources()
|
refreshResources()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[loaded, refreshResources, running],
|
[loaded, refreshResources, running, refreshOnStart],
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue