import type { Strapi4RequestParams } from '../types/v4' ; import { useStrapiVersion } from './useStrapiVersion' ; import { useStrapiClient } from './useStrapiClient' ; export const useStrapi4 = ( ) => { const client = useStrapiClient ( ) ; const version = useStrapiVersion ( ) ; if ( version !== 'v4' ) { console . warn ( 'useStrapi4 is only available for v4' ) ; } param { string } contentType param { Strapi4RequestParams } params returns const find = < T > ( contentType , params ? ) : Promise < T > => { return client ( `/${ contentType }` , { method : 'GET' , params } ) ; } ; param { string } contentType param { string | number } id param { Strapi4RequestParams } params returns const findOne = < T > ( contentType , id , params ? ) : Promise < T > => { return client ( `/${ contentType }/${ id }` , { method : 'GET' , params } ) ; } ; param { string } contentType param { Record < string , any > } data returns const create = < T > ( contentType , data ) : Promise < T > => { return client ( `/${ contentType }` , { method : 'POST' , body : { data } } ) ; } ; param { string } contentType param { string | number } id param { Record < string , any > } data returns const update = < T > ( contentType , id , data ? ) : Promise < T > => { if ( typeof id === 'object' ) { data = id ; id = undefined ; } const path = [ contentType , id ] . filter ( Boolean ) . join ( '/' ) ; return client ( path , { method : 'PUT' , body : { data } } ) ; } ; param { string } contentType param { string | number } id returns const _delete = < T > ( contentType , id ? ) : Promise < T > => { const path = [ contentType , id ] . filter ( Boolean ) . join ( '/' ) ; return client ( path , { method : 'DELETE' } ) ; } ; return { find , findOne , create , update , delete : _delete } ; } ;