Skip to content

Commit 3b69810

Browse files
authored
Fix the jslint warning (or infinate loop error when fixed) from useSelect usage (#651)
1 parent 16f26cf commit 3b69810

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/editor-sidebar/create-panel.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,24 @@ import ScreenHeader from './screen-header';
2828
export const CreateThemePanel = ( { createType } ) => {
2929
const { createErrorNotice } = useDispatch( noticesStore );
3030

31+
const subfolder = useSelect( ( select ) => {
32+
const stylesheet = select( 'core' ).getCurrentTheme().stylesheet;
33+
if ( stylesheet.lastIndexOf( '/' ) > 1 ) {
34+
return stylesheet.substring( 0, stylesheet.lastIndexOf( '/' ) );
35+
}
36+
return '';
37+
}, [] );
38+
3139
const [ theme, setTheme ] = useState( {
3240
name: '',
3341
description: '',
3442
uri: '',
3543
author: '',
3644
author_uri: '',
3745
tags_custom: '',
38-
subfolder: '',
46+
subfolder,
3947
} );
4048

41-
useSelect( ( select ) => {
42-
const themeData = select( 'core' ).getCurrentTheme();
43-
setTheme( {
44-
...theme,
45-
subfolder:
46-
themeData.stylesheet.lastIndexOf( '/' ) > 1
47-
? themeData.stylesheet.substring(
48-
0,
49-
themeData.stylesheet.lastIndexOf( '/' )
50-
)
51-
: '',
52-
} );
53-
}, [] );
54-
5549
const cloneTheme = () => {
5650
if ( createType === 'createClone' ) {
5751
handleCloneClick();

0 commit comments

Comments
 (0)