11import React , {
2- useState , useCallback , useContext ,
3- useEffect , useMemo
2+ useState ,
3+ useCallback ,
4+ useContext ,
5+ useEffect ,
46} from 'react' ;
57import PropTypes from 'prop-types' ;
68import useDeepCompareEffect from 'use-deep-compare-effect' ;
9+ import { useDeepCompareCallback } from 'use-deep-compare' ;
710
811import {
912 getContentFromFile , saveFile , ensureFile , deleteFile ,
@@ -37,7 +40,7 @@ function useFile({
3740 const branch = repository && ( repository . branch || repository . default_branch ) ;
3841 const [ deleted , setDeleted ] = useState ( ) ;
3942
40- const _setBlob = useCallback ( async ( _blob ) => {
43+ const _setBlob = useDeepCompareCallback ( async ( _blob ) => {
4144 if ( blob && _blob && typeof onConfirmClose == 'function' ) {
4245 const confirm = await onConfirmClose ( )
4346
@@ -71,7 +74,7 @@ function useFile({
7174 } ;
7275 } , [ onFilepath ] ) ;
7376
74- const load = useCallback ( async ( ) => {
77+ const load = useDeepCompareCallback ( async ( ) => {
7578 if ( config && repository && filepath ) {
7679 const _file = await ensureFile ( {
7780 filepath, defaultContent, authentication, config, repository, branch, onOpenValidation,
@@ -80,8 +83,7 @@ function useFile({
8083 console . log ( "ensureFile:" , _file ) ;
8184
8285 let defaultCachedContentFile ;
83- if ( onLoadCache && _file && _file . html_url )
84- {
86+ if ( onLoadCache && _file && _file . html_url ) {
8587 defaultCachedContentFile = await onLoadCache ( { authentication, repository, branch, html_url : _file . html_url , file : _file } ) ;
8688 }
8789
@@ -113,7 +115,7 @@ function useFile({
113115 defaultContent , authentication , branch , onOpenValidation
114116 ] ) ;
115117
116- const createFile = useCallback ( async ( {
118+ const createFile = useDeepCompareCallback ( async ( {
117119 branch : _branch , filepath : _filepath , defaultContent : _defaultContent , onOpenValidation,
118120 } ) => {
119121 if ( config && repository ) {
@@ -132,7 +134,7 @@ function useFile({
132134 }
133135 } , [ authentication , config , repository , updateBranch , onFilepath ] ) ;
134136
135- const close = useCallback ( ( ) => {
137+ const close = useDeepCompareCallback ( ( ) => {
136138 if ( blobActions && blobActions . close ) {
137139 blobActions . close ( ) ;
138140 } ;
@@ -143,13 +145,13 @@ function useFile({
143145 update ( ) ;
144146 } , [ update , blobActions , onFilepath ] ) ;
145147
146- const saveCache = useCallback ( async ( content ) => {
148+ const saveCache = useDeepCompareCallback ( async ( content ) => {
147149 if ( onSaveCache ) {
148150 await onSaveCache ( { authentication, repository, branch, file, content} ) ;
149151 }
150152 } , [ writeable , authentication , repository , branch , file , onSaveCache ] ) ;
151153
152- const save = useCallback ( async ( content ) => {
154+ const save = useDeepCompareCallback ( async ( content ) => {
153155 //console.log("GRT save // will save file");
154156 await saveFile ( {
155157 authentication, repository, branch, file, content,
@@ -163,7 +165,7 @@ function useFile({
163165 ) ;
164166 } , [ writeable , authentication , repository , branch , file , load , saveFile , saveCache ] ) ;
165167
166- const dangerouslyDelete = useCallback ( async ( ) => {
168+ const dangerouslyDelete = useDeepCompareCallback ( async ( ) => {
167169 if ( writeable ) {
168170 const _deleted = await deleteFile ( {
169171 authentication, repository, file, branch,
0 commit comments