mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
Updated api services to be memoized in case of re-renders
no issue
This commit is contained in:
parent
446841ce9c
commit
c1628f46e0
@ -1,4 +1,4 @@
|
||||
import React, {createContext} from 'react';
|
||||
import React, {createContext, useMemo} from 'react';
|
||||
import setupGhostApi from '../../utils/api';
|
||||
|
||||
export interface FileService {
|
||||
@ -20,14 +20,14 @@ const ServicesContext = createContext<ServicesContextProps>({
|
||||
});
|
||||
|
||||
const ServicesProvider: React.FC<ServicesProviderProps> = ({children, ghostVersion}) => {
|
||||
// TODO: Will this re-render? (if so, will it make duplicate requests because the api object is different?)
|
||||
const apiService = setupGhostApi({ghostVersion});
|
||||
const fileService = {
|
||||
const apiService = useMemo(() => setupGhostApi({ghostVersion}), [ghostVersion]);
|
||||
const fileService = useMemo(() => ({
|
||||
uploadImage: async (file: File): Promise<string> => {
|
||||
const response = await apiService.images.upload({file});
|
||||
return response.images[0].url;
|
||||
}
|
||||
};
|
||||
}), [apiService]);
|
||||
|
||||
return (
|
||||
<ServicesContext.Provider value={{
|
||||
api: apiService,
|
||||
|
Loading…
Reference in New Issue
Block a user